Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Two digit prefix to variables


From   [email protected]
To   [email protected]
Subject   Re: st: Two digit prefix to variables
Date   Thu, 1 Jul 2004 15:34:44 -0400

Thanks Scott,

I just figured out it couldn't be a number. I think I'll use the first of your
suggestions.

Reza

Quoting [email protected]:

> Reza,
>
> names have to begin with a letter or an underscore.
>
> So, how about:
>
>  foreach var of varlist * {
>  	rename `var' _95_`var'
>  	}
>
> or
>
>  foreach var of varlist * {
>  	rename `var' `var'_95
>  	}
>
> Scott
>
>
> ----- Original Message -----
> From: [email protected]
> Date: Thursday, July 1, 2004 2:22 pm
> Subject: Re: st: Two digit prefix to variables
>
> > Thanks Scott,
> >
> > I tried your code and it worked perfectly. However, when I tried
> > to use a
> > numerical prefix, it gave me the following error message:
> >
> > foreach var of varlist * {
> >  2. rename `var'  95_`var'
> >  3. }
> > 95_district invalid name
> > r(198);
> >
> > Any idea why this is happening? I'm sure its simple & I'm just too
> > unfamiliarwith the code. I'll read up more on "foreach".
> >
> > Thanks,
> > Reza
> >
> >
> >
> >
> > Quoting [email protected]:
> >
> > > foreach var of varlist * {
> > > 	rename `var' foo_`var'
> > > 	}
> > >
> > > Hope this helps,
> > > Scott
> > >
> > >
> > > ----- Original Message -----
> > > From: [email protected]
> > > Date: Thursday, July 1, 2004 1:59 pm
> > > Subject: Re: st: Two digit prefix to variables
> > >
> > > > Regarding my earlier message:
> > > >
> > > > I wanted to add that I am not looking to type "rename var 95var"
> > > > for every
> > > > variable. I would like to write and use a program to effect the
> > > > change.
> > > > Thanks,
> > > > Reza
> > > >
> > > > Quoting [email protected]:
> > > >
> > > > > Dear Statalisters,
> > > > >
> > > > > Could you please help me work out how to attach a two digit
> > > > numerical prefix
> > > > > to
> > > > > all my variables? I am preparing to append surveys from
> > > > different dates but
> > > > > that have the same variable names, and I would like to
> > > > distinguish between
> > > > > them
> > > > > by adding a two digit year prefix (e.g. hhid becomes 95hhid).
> > > > This will be
> > > > > done
> > > > > before appending the datasets, so that when I do append I can
> > > > distinguish> between the variables.
> > > > >
> > > > > I have not yet taken the Stata programming course (hope to
> > > > soon), so I'm
> > > > > unsure
> > > > > where to start.
> > > >
> > >
> > > *
> > > *   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/
>


*
*   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