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: Keeping the same variable with collapse- Reference to Sep.2002 posting
From
"Henao Arbelaez, Camila" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
st: Keeping the same variable with collapse- Reference to Sep.2002 posting
Date
Tue, 8 May 2012 13:12:41 -0400
In the FAQ (Nicholas Cox, Sept. 2002/updated Sept. 2003) I found instructions on how to keep the original variable labels after collapsing a dataset. I only changed the variable list (on which to apply the loop), but when I run I have a "invalid syntax" problem.
My code runs as following. Maybe you can help me figure out what is wrong. The loop which presents the problem is the last one.
*1. Copy variable labels before collapse
foreach v in offshore-merge_gpdusd {
local l`v' : variable label `v'
if `"`l`v''"' == "" {
local l`v' "`v'"
}
}
local list offshore-merge_gpdusd
*2.Collapse
collapse (mean) offshore-merge_gpdusd, by(country year ifs)
*3. Label original variables with the local created in step 1.
foreach v in offshore- merge_gpdusd {
label var `v' "`l`v''"
}
Thanks for your help,
Camila
*
* 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/