Statalist The Stata Listserver


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

Re: st: Re: reshape when the stub is at the beginning of the variables


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   Re: st: Re: reshape when the stub is at the beginning of the variables
Date   Wed, 26 Apr 2006 11:53:54 +0900

Michael Blasnik wrote:

Check out the advanced syntax for reshape.  I believe that you can specify
the location of the "j" part of the variable names using the @ symbol.  I
haven't used this option in a while, but I think you will need to specify
that the j variable is a string and may need to use the atwl() option for
the reshape xij line.

--------------------------------------------------------------------------------

I never seriously looked into -reshape-'s advanced syntax instructions
before, and instead used the renaming method that Neil Shephard showed.

But the advanced-syntax -reshape- method is faster and easier once you get
the hang of it.

Joseph coveney

clear
set more off
set seed `=date("2006-04-26", "ymd")'
set obs 100
foreach letter in `c(ALPHA)' {
   generate byte `letter'SMOKES = uniform() > 0.5
   replace `letter'SMOKES = .n if uniform() > 0.9
}
generate byte ID = _n
*
* Begin here
*
reshape i ID
reshape j WAVE, string
reshape xij @SMOKES
reshape query // Optional--just to examine
reshape long
exit

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