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" <[email protected]>
To   <[email protected]>
Subject   RE: st: RE: RE: Another reshape wide question
Date   Wed, 19 Apr 2006 13:44:27 +0100

Specific replies below. 

Nick 
[email protected] 

Rachel (a.k.a. Amber Katz) 
 
> Thanks.  Actually, I am going to reshape wide using the "string"
> option, so A, B and C will be fine.

Not my point at all. My point is that for example 

<whatever>1A 
<whatever>2A
<whatever>3A 

are not in stub + suffix form. 
 
> The problem is creating the duplicate variables GenderA, GenderB and
> GenderC from Gender, and so forth.   Is there an easy way to do this? 

Yes, there is, but if these variables don't exist as separates you 
don't need to create them. 

> Also, is there a way to have Stata "automatically" find variables that
> don't have A, B and C suffixes?  Some sort of "if *A" command?

Yes, there is, but again I don't see that you need this.

Nick Cox 

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

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