Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: RE: Renaming year-quarter indicators with a local


From   "Davide Cantoni" <[email protected]>
To   [email protected]
Subject   Re: st: RE: Renaming year-quarter indicators with a local
Date   Sun, 20 Jan 2008 23:15:33 +0100

Nick, thanks for picking up this unresolved question. In fact, by
using your trick with the the "|  |" you can see that there is some
space in front of the text:

*-------------- Begin Output --------------*
. 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);
*-------------- End Output --------------*

And that would explain in fact why the rename command does not work.
There is a tab space in front of 92_3.

Thanks also for your suggestion to use the "trim" function. In that
case, it works fine and it solved my problem.

But still, I wonder why the simpler version of that local macro does
not work. Besides, I asked some colleagues to run that code and it did
not work for them either. Any ideas? Is it Stata-9-specific?

Davide



On 20/01/2008, Nick Cox <[email protected]> wrote:
> 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/
>
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index