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]
Re: st: Keeping the same variable with collapse- Reference to Sep.2002 posting
From
Nick Cox <[email protected]>
To
[email protected]
Subject
Re: st: Keeping the same variable with collapse- Reference to Sep.2002 posting
Date
Tue, 8 May 2012 18:25:30 +0100
The specific reference here is, or should be,
FAQ . . . . . . . . . . . . Keeping the same variable labels with collapse
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
2/03 How can I collapse my dataset and keep the same
variable labels?
http://www.stata.com/support/faqs/data/variables.html
and your problem is that you are not following the advice! It is easy
to fix, however.
Where you have e.g.
foreach v in offshore-merge_gpdusd
that should be
foreach v of var offshore-merge_gpdusd
The FAQ examples all have that form.
Nick
On Tue, May 8, 2012 at 6:12 PM, Henao Arbelaez, Camila
<[email protected]> wrote:
> 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,
*
* 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/