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/