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

st: Re: extract variable name

From   Kit Baum <>
Subject   st: Re: extract variable name
Date   Wed, 3 Aug 2005 08:14:10 -0400

It is not necessary to go through that much work to deal with the two- digit year. Here is a snippet that I wrote yesterday to deal with that problem in a data set which has yr_0, ... yr_4 as date strings in two-digit year format:

forv i=0/4 {
g meet_yr`i' = date(yr_`i',"dm20y")
replace meet_yr`i' = meet_yr`i' - 36525 if meet_yr`i' > 32783
format meet_yr`i' %td
drop yr_`i'

The constant 36525 is the number of days in the interval (xx xxx 19xx - xx xxx 20xx).

Kit Baum, Boston College Economics

On Aug 3, 2005, at 2:33 AM, Jeppe wrote:

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

*   For searches and help try:

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