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   "Austin Nichols" <[email protected]>
To   [email protected], [email protected], [email protected]
Subject   Re: st: Re: reshape when the stub is at the beginning of the variables
Date   Wed, 26 Apr 2006 15:57:49 -0400

This advice might be too late to be useful, but...
use of -reshape-'s advanced syntax is very handy for many things, but
if you've got one set of variables that has wave indexed by A, B, C
and one indexed by 1, 2, 3 then I think the rename approach is the
best one:

clear
set obs 20
forv i=1/3 {
 local ltr=char(`i'+64)
 g `ltr'SMOK=uniform()>0.5 if uniform()>.1
 g `ltr'DRNK=uniform()>0.5
 g wave`i'=uniform()>.2
 }
generate byte ID = _n
order ID wave*
li in 1/5, noo
ds
foreach v in `r(varlist)' {
 forv i=1/3 {
  local ltr=char(`i'+64)
  local stub=substr("`v'",2,.)
  if substr("`v'",1,1)=="`ltr'" ren `v' `stub'`i'
  }
 }
reshape long wave SMOK DRNK, i(ID)
ren wave appears
la var appears "Indiv appears in wave"
ren _j wave
la var wave "Wave of observation"

On 4/26/06, Nick Cox <[email protected]> wrote:
> Various suggestions were made in this thread. In
> general, use of -reshape-'s advanced syntax seems
> most direct to me. But renaming solutions are
> of interest for many other problems and I will
> focus on those.

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