Statalist The Stata Listserver


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

RE: st: RE: RE: Another reshape wide question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: RE: Another reshape wide question
Date   Tue, 18 Apr 2006 18:39:31 +0100

My guess is that you need to do more renaming. 

The key principle here is that -reshape- thinks 
of variable names to be -reshape-d as 

stub + suffix

So, I think you need to -rename- (e.g.) 

Opinion?C 

as 

OpinionC? 

-renvars- is one way to do it which 
some people like, and some don't. 
It's more instructive
to do it from first principles. 
That could be 

foreach v of var Opinion?? { 
	local letter = substr("`v'",-1,1) 
	local digit = substr("`v'",-2,1) 
	rename `v' Opinion`letter'`digit' 
} 

With that it seems that the key variables
would all have suffixes 1-3. 

Nick 
n.j.cox@durham.ac.uk 

Amber Katz
 
> Suppose that, for each individual and for each round, I have the
> following variables:
> OpinionA OpinionB OpinionC.  Now suppose I have many variables that
> are individual-specific and do not differ among products: Gender,
> Married, Nationality, etc.
> 
> What I'd like is to have the variable in form:
> ID Opinion1A-Opinion3A Opinion1B-Opinion3B Opinion1C-Opinion3C Gender
> Married Nationality.
> 
> So I need to do a reshape long on the opinion variables by product (A,
> B, and C).  I'd like to do this without generating GenderA-GenderC,
> MarriedA-MarriedC and NationalityA-NationalityC variables as I have
> many of these.
> 
> My data was originally in long form, so I did a renvars and reshape
> wide (on the subvariable "round"), and the data is now of form
> ID Opinion1A-Opinion3A [Opinion*B and Opinion*C blank] Gender1-3
> Married1-3 Nationality1-3
> ID [Opinion*A and Opinion*C blank] Opinion1B-Opinion3B  Gender1-3
> Married1-3 Nationality1-3
> ID [Opinion*A and Opinion*B blank] Opinion1C-Opinion3C  Gender1-3
> Married1-3 Nationality1-3
> 
> I'd like to convert into the long form (by product) specified above.
> 

*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index