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

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

From   "Jia Xiangping" <>
Subject   st: -reshape- with more than one j()?
Date   Fri, 29 Feb 2008 14:34:05 -0500

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

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:

© Copyright 1996–2017 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index