Thursday, September 2, 2010

OUT OF (re)SHAPE: long to wide

I am NOT a fan of the reshape command, if there are other ways, i really avoid it like a plague.



Say you have a data set with members as unit of observation.  Each observation has a tag, identifying its household and its “count” in the household. 

Say, the problem is transforming the data set into one where the unit of observation is the household.

If I am interested only with a few household characteristics, I WOULD RATHER NOT USE the reshape command.  



I would rather use the egen command and then using the following technique:

sort hhid:
by hhid: egen aveincome=mean(income)
gen count=sum(1)
drop if count~=1
keep hhid aveincome

TAPOS! WALA NG KUSKUS BALUNGOS!

Problem with reshape (long to wide pa lang ito ha), you would have a lot of income variables depending on the family with the most number of members.  And you will be forced to include in the reshape command variables you are actually not interested with (since these vars may not be constant within the ids).

But sige na nga, here is a sample of the darn RESHAPE command.

No comments:

Post a Comment