1
votes

Why do I get a "invalid name" (see last line)?

tempname vector
postfile `vector' beta_lag    beta_const /// 
              se_mvalue   se_const   /// 
          using vettore, replace

xtreg Perf lag if t>=396 & t<=408
post `vector' (_b[lag])  (_b[_cons]) ///
              (_se[lag]) (_se[_cons])

RESULT:

. (regression is ok, omitted result...)
. post `vector'  (_b[lag])  (_b[_cons]) (_se[lag]) (_se[_cons])
( invalid name

Thank you in advance

1
Are you running this as one block of code in the same place? If not, Stata may not be able to see the name vector and be choking on the ( as the next token and as an unacceptable handle. - Nick Cox
I am executing it from a .do , I select the piece of code (after loading the data) and ctrl+D. - Giuseppe
Try running the code as a whole then. - Nick Cox
That's what I am doing, obviously. It stops at that error - Giuseppe
I couldn't reproduce your problem changing only the -xtreg- statement to -regress- in the auto data set and changing the identity of the variables in the -post- statement. I would suggest a copy and paste of your -post- statement from your Stackoverflow post into the Stata editor. Also, open a new do file editor; copy and paste into that; but write the -post- statement by hand. - Steve Samuels

1 Answers

0
votes

It's not obvious what you are doing, contrary to assertion. This code segment illustrates technique and you should be able to reproduce its running without error.

webuse nlswork, clear 
xtset idcode
tempname myout 
postfile `myout' constant grade age using myout.dta
xtreg ln_w grade age 
post `myout' (_b[_cons]) (_b[grade]) (_b[age]) 
postclose `myout' 
describe using myout 

The example shows that using expressions such as _b[_cons] is fine, in case there were any doubt.

My conjecture remains that the post command cannot see the tempname (vector in your example) and is thus evaluating it as an empty string. The first token it detects is the first ( which cannot be part of an acceptable file handle, so it complains.

This problem could (will) arise if you define the tempname in a different locale. That could be for example that part of the code is run in the main interactive session and part from a do-file or do-file editor. It could also be if you select the code to run in parts (e.g. selecting individual lines and running them individually).