Statalist


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

Re: st: -reshape- with more than one j()?


From   "Friedrich Huebler" <fhuebler@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: -reshape- with more than one j()?
Date   Fri, 29 Feb 2008 15:53:13 -0500

Xiangping Jia,

gen x_good_manure = x if Seed=="good" & Fert=="manure"
gen x_good_chem = x if Seed=="good" & Fert=="chem"
gen x_bad_manure = x if Seed=="bad" & Fert=="manure"
gen x_bad_chem = x if Seed=="bad" & Fert=="chem"
collapse x_good_manure - x_bad_chem, by(ID)

Friedrich

On Fri, Feb 29, 2008 at 2:34 PM, Jia Xiangping <jiajoseph@googlemail.com> wrote:
> Dear all,
>
>  After several collapsing, I have such a data,
>
>  ID      Seed    Fert    x
>  1       good    mamure  3
>  1       good    chem.   4
>  1       bad     chem.   2
>  1       bad     manuure 1
>
>  But I need to further collapse to:
>  ID   x_good_maure       x_good_chem   x_bad_manure  x_bad_chem
>
>  The crude way I can figure out is:
>  collapse (sum) x if fert==manure , by(ID Seed)
>  reshape wide x, i(ID) j(seed)
>  sort id
>  save file1
>
>  collapse (sum) x if fert==chem., by(ID Seed)
>  reshapce wide x, i(ID) j(Seed)
>  sort id
>  save file2
>  merge....
>
>  My questions is: Do we have some other options (say, forvalues by
>  group or reshape with more than one 'j()' ?  Yes, for sure. I can also
>  use forvalues like this:
>  forvalues i=1/6 {
>  collapse (sum) x if fert==`i', by(ID Seed)
>  reshape wide x, i(ID) j(Seed)
>  sord ID
>  save file`i'
>  }
>
>  But that is not an improvement at all.....
>
>
>  --
>  Xiangping Jia
*
*   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