The command is reshape see-> - whelp reshape -
But if that what you have pasted is your true dataset then only the
first observation within each group contains the group number, which
makes it a bit difficult. First, I would fill up the missing HH
identifier. You could do it in this way (which will ONLY work if your
dataset looks EXACTLY the way you posted it!).
// Filling up the missing HH (works
replace HH=HH[_n-1] if missing(HH[_n])
// reshaping the dataset to wide
reshape wide Income, i(HH) j(Code)
/* gives you the following (period indicates missing value, assuming
Income is numeric):
HH Income1 Income2 Income3 Income4
1 1000 500 100 .
2 900 . . 300
3 800 300 500 400
*/
// It looks like you want the missings created during the reshape to
be replaced by ZEROs
// so:
foreach var of varlist Income* {
replace `var'=0 if `var'==.
}
// Does this work out for you?
sebastian
On Wed, 02 Mar 2005 16:12:18 +0700, Ueda, Takeshi (FAORAP)
<[email protected]> wrote:
>
>
>
> I want to reshape Data Set 1 to Data Set 2. Please advise me how I can do
> it in an efficient way. The real data set to be dealt with contains over
> 60,000 HHs and over 200 Codes. Thank you very much.
>
> T. Ueda
>
> <Data Set 1>
> HH Code Income
> 1 1 1000
> 2 500
> 3 100
> 2 1 900
> 4 300
> 3 1 800
> 2 300
> 3 500
> 4 400
>
> <Data Set 2>
> HH Code1 Code2 Code3 Code4
> 1 1000 500 100 0
> 2 900 0 0 300
> 3 800 300 500 400
--
- Seb F Buechte
-
- Stay tuned!
*
* 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/