In addition to other suggestions, note that you'd need to standardise on "manure".
Nick
[email protected]
Jia Xiangping
As both -seed- and -fert- have several categories, Phil's approach is
more efficient. Thanks both of you, Phil and Friedrich.
.
On 2/29/08, Phil Schumm <[email protected]> wrote:
> On Fri, Feb 29, 2008 at 2:34 PM, Jia Xiangping
> <[email protected]> wrote:
> > 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
>
>
> . gen foo = Seed + "_" + subinstr(Fert,".","",.)
>
> . drop Seed Fert
>
> . ren x x_
>
> . reshape wide x_, i(ID) j(foo) string
> <output omitted>
>
> . li, ab(14)
>
> +--------------------------------------------------------------+
> | ID x_bad_chem x_bad_manure x_good_chem x_good_manure |
> |--------------------------------------------------------------|
> 1. | 1 2 1 4 3 |
> +--------------------------------------------------------------+
*
* 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/