Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: UPDATE: once again -reshape- and labels


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: UPDATE: once again -reshape- and labels
Date   Tue, 17 Jun 2008 15:44:14 +0100

Roy Wada posted a program which solves Andrea's problem. That still
leaves the question of what was wrong with Andrea's code, mainly a
matter of straightening out the locals. 

Here is one re-working. We can pick up the label for Ax from Ax1, etc. 

local rshp "Ax Bx Cx"

/* store label of each group of variables */
foreach v of local rshp {
        local l`v' : variable label `v'1
}

/* reshape */
quietly reshape long `rshp', i(id) j(wave) 
/* giving dataset with variables id, Ax, Bx, Cx, wave */

/* set label */
 foreach v of local rshp {
      label variable `v' "`l`v''"
}

Nick
[email protected] 

Andrea Bennett

I'm sorry but your suggestion does not work. As - hopefully clear to  
all - I have described, it is about temporarily saving the label for  
e.g. Ax1 and then - after reshape long - apply the label of Ax1 to Ax.  
This should be automated for all variables I want to reshape so that I  
won't have to change the labels manually.

But thanks for the try!

On Jun 16, 2008, at 11:04 PM, Steichen, Thomas J. wrote:

> In your last foreach loop:
>
> foreach v of var `rshp' {
>        label variable `v' "`l`lrshp''"
> }
>
> You are iterating thru values of `rshp' but are selecting labels from
> something called `l`lrshp''.
>
> I suspect that something should be `l`rshp''.
>
> (i.e., you have the "l" in there twice.)

Andrea Bennett

> So with a more detailed question again (see previous post by me). The
> data set contains these variables: id, Ax1-Ax10, Bx1-Bx10, Cx1-Cx10.
> Every group (e.g. Ax1-Ax10) has the very same label which should be
> applied to the new variables after reshape. This is the code I got so
> far:
>
> /* store label of each group of variables */
> local lrshp "Ax1 Bx1 Cx1"
>
> foreach v of var `lrshp' {
>        local l`v' : variable label `v'
> }
>
> /* reshape */
> local rshp "Ax Bx Cx"
> quietly reshape long `rshp', i(id) j(wave) /* giving me a data set
> with the variables: id, Ax, Bx, Cx, wave */
>
> /* set label */
> foreach v of var `rshp' {
>        label variable `v' "`l`lrshp''"
> }
>
>
> This way, Ax gets the correct label but Bx and Cx get the label of Ax.
> I seem to do something wrong when iterating at the end. I just really
> don't see the point.

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