Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: RE: -foreach-, local macro, -split- command


From   Austin Nichols <austinnichols@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: RE: -foreach-, local macro, -split- command
Date   Tue, 8 Sep 2009 21:18:48 -0400

Nick already gave the answer I would have given:

Your problem is clearer this way, but I can't see an alternative to
working with several variables simultaneously, or indeed why you think
that's so bad.

In other words: If you are doing

g generatedvar=""
levelsof wais, local(lev)
foreach l of lev {
 replace generatedvar="`l' "+generatedvar
* plus whatever qualifiers etc.
 }
ren generatedvar g
split g
g i=_n
reshape long g, i(i) j(j)

you need to instead

levelsof wais, local(lev)
loc j=1
foreach l of lev {
 g g`j'="`l'"
* plus whatever qualifiers etc.
 loc j=`j'+1
}
g i=_n
reshape long g, i(i) j(j)

i.e. make separate variables in the first place.  You can also avoid
the -reshape- using a different approach.  It's not clear why you want
to do any of this, though, so maybe there is a better global approach.


On Tue, Sep 8, 2009 at 8:15 PM, David Torres<torresd@umich.edu> wrote:
> I ran this one once and it looks like it may be useful.  It's getting late
> here, though, so I'll respond more fully tomorrow if I should have any other
> questions.
>
> Thanks for -logout-.
>
> Give this guy a raise; it's people like him who make things easier for
> technological inepts like me.
>
> ;-D
>
> David Torres

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



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