Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
st: Populating time series records with values from different "Year" columns (rep78, rep79...)
From
"Robak, Anna Michelle - robam013" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Populating time series records with values from different "Year" columns (rep78, rep79...)
Date
Wed, 21 Dec 2011 21:19:12 +0000
Dear List,
I want to populate a variable "annrep" with values from variables rep78, rep79...rep118, where the first annrep record takes the value from rep78, the second takes the value from rep79, etc. But rather than taking the value from rep78, rep79...rep118, Stata is simply entering 'rep78', 'rep79'...
I expanded my records to create time series data, and generated a new variable "Year". For each Year, I want to grab the appropriate rate from columns rep78, rep79, etc, but I can't seem to get Stata to recognise my concatenated string as a variable name. This is a simplified version of the command I tried, using just rep78 and rep79:
sysuse auto, clear
gen rep79=rep78+1
expand 2
by make,sort: gen Year=1977+_n
by make: gen annrep=strtoname("rep"+string(77+_n),1) if Year==1977+_n
which returns 'rep78' rather than the value from column 'rep78'.
Looking forward to your help!
Kind Regards,
Anna
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/