Hmm ok, thank you, I shall have a look at that.
I'm afraid i made an oversimplification in stating my problem: the
variable names are not actually var1_ var2_ var3_ ... but words:
something_ somethingelse_
So my question still stands: how do I get the name of a variable and
put it in a local string for each iteration
On 8/2/05, R.E. De Hoyos <[email protected]> wrote:
> Jeppe,
>
> You can try
>
> local year 88 89 90 91 92 93 94 95 96 97 98 99 00 01 02
>
> foreach y in local years {
> forval i = 1/100 {
> if `y'>=88 {
> ren var`i'_`y' var`i'_19`y'
> }
> else {
> ren var`i'_`y' var`i'_20`y'
> }
> }
> }
>
> I haven't tried it, so I hope it works.
>
> Rafa
> ________________________
> R.E. De Hoyos
> Faculty of Economics
> University of Cambridge
> CB3 9DE, UK
> www.econ.cam.ac.uk/phd/red29/
>
>
> ----- Original Message -----
> From: "Jeppe Warberg Larsen" <[email protected]>
> To: <[email protected]>
> Sent: Tuesday, August 02, 2005 1:14 PM
> Subject: st: Extract variable name in order to change it, iteratively
>
>
> >I have a wide data structure. Each observation consists of a unique
> > identifier (say, id) and some series of annual variables with a
> > two-digit suffix (running in different intervals). Like this:
> >
> > id var1_88 var1_89 ... var1_02 var2_92 var2_93 ... var2_02
> > var3_...................................
> >
> > Now I want to reshape it to long, but stata fails to read the
> > two-digit values after the turn of century (00 01 02), so I need to
> > rename all varibles to a four-digit year.
> >
> > foreach var of varlist var1_88-var100_02{
> > //save name of variable in a local string
> > //do nessecary string manipulation (I can do that)
> > //rename var
> > }
> >
> > My problem seems to be:
> > 1) extracting the name of the current variable
> > 2) rename
> >
> > Do you understand what I'm asking?
> > I'd be glad if someone can help, and please don't tell me that it
> > would be easier to do this manually, because I will need to do this
> > operation many times...
> >
> > Jeppe W. Larsen
> >
> > *
> > * 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/
>
*
* 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/