I have no problems with this code in Stata 10.
To echo Thomas' comment:
Your output seems to show extra leading spaces in the display.
Try this variant to see whether the "| |" bound some spaces
as well.
clear
set obs 3
gen _Idate_130 = 0
rename _Idate_130 _Iquarter_92_2
local qtr: display %tqY!_q 130
di "|`qtr'|"
gen _Idate_131 = 0
rename _Idate_131 _Iquarter_`qtr'
If so, you may need to try something more like
clear
set obs 3
gen _Idate_130 = 0
rename _Idate_130 _Iquarter_92_2
local qtr = trim("`: display %tqY!_q 130'")
gen _Idate_131 = 0
rename _Idate_131 _Iquarter_`qtr'
Nick
[email protected]
Davide Cantoni
Thanks, Thomas. Alas it does not work that well in my case. And it's
not because there is a space after _Iquarter_. Now I just copied and
pasted each one of your command lines, just to be sure, and:
*--------------------------*
. clear
. set obs 3
obs was 0, now 3
. gen _Idate_130 = 0
. rename _Idate_130 _Iquarter_92_2
. local qtr: display %tqY!_q 130
. di "`qtr'"
92_3
. gen _Idate_131 = 0
. rename _Idate_131 _Iquarter_`qtr'
92_3 not allowed
r(101);
*--------------------------*
I have no idea why this is happening on my Stata. (btw, Intercooled
Stata 9.2. for Macintosh).
Thomas Steichen
> Works fine for me.
> The implication of the error is that you must have had a space after
> _Iquarter_ and before `qtr'.
>
> Here's my test code:
>
> .. clear
> .. set obs 3
> obs was 0, now 3
>
> .. gen _Idate_130 = 0
> .. rename _Idate_130 _Iquarter_92_2
>
> .. local qtr: display %tqY!_q 130
> .. di "`qtr'"
> 92_3
>
> .. gen _Idate_131 = 0
> .. rename _Idate_131 _Iquarter_`qtr'
>
> .. desc
>
> Contains data
> obs: 3
> vars: 2
> size: 36 (99.9% of memory free)
>
------------------------------------------------------------------------
-------
> storage display value
> variable name type format label variable label
>
------------------------------------------------------------------------
-------
> _Iquarter_92_2 float %9.0g
> _Iquarter_92_3 float %9.0g
>
------------------------------------------------------------------------
-------
> Sorted by:
>
> ..
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/