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   "Amber Katz" <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: Another reshape wide question
Date   Tue, 18 Apr 2006 14:33:18 -0400

Thanks.  Actually, I am going to reshape wide using the "string"
option, so A, B and C will be fine.

The problem is creating the duplicate variables GenderA, GenderB and
GenderC from Gender, and so forth.   Is there an easy way to do this? 
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?


Again, thanks for all your help, Nick.

Rachel

On 4/18/06, Nick Cox <[email protected]> wrote:
> 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
> [email protected]
>
> 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/
>

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