Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: reshaping with multiple identifiers
From
Eric Booth <[email protected]>
To
[email protected]
Subject
Re: st: reshaping with multiple identifiers
Date
Sat, 31 Mar 2012 14:53:44 -0500
<>
Mintewab:
Running the commands you gave yesterday (with some clean-up and adding vars you forgot to include (like 'mavg')) gives:
**********************!
clear
inp str11(s25q3) hhid kebele year mo
"maize" 1 1 2006 1
"potatoes" 1 1 2005 1
"grass" 1 1 2004 1
"sinar/ge" 1 1 2003 1
"sinar/ge" 1 1 2002 1
end
g mavg = runiform()
egen both=group(year mo ), label //labels won't help you here
drop year mo
**you don't need 'new' since i() takes a varlist
reshape wide mavg , i(kebele hhid s25q3) j(both)
list, noobs
/* which gives:
+--------------------------------------------------------------------------------+
| s25q3 hhid kebele mavg1 mavg2 mavg3 mavg4 mavg5 |
|--------------------------------------------------------------------------------|
| grass 1 1 . . .3713805 . . |
| maize 1 1 . . . . .1650207 |
| potatoes 1 1 . . . .760604 . |
| sinar/ge 1 1 .9678735 .3795409 . . . |
+--------------------------------------------------------------------------------+
*/
**********************!
I'm not sure what you expected here, but you got what you asked for. The reason 'mavg*' is missing in the wide version is that there was no data in the long version of the data. That is, the 'mavg*' vars are non-missing in only 'mavg3' in the first observation because for the i() grass, hhid==1, kebele==1, you only have one observation in the original, long dataset (in 2004, month 1, which become the 3rd 'mavg' var in your wide data since it's the 3rd "group" of your j() var 'both').
If you expected something else, please describe with more detail (or better give an example of what you are trying to get -reshape- to do for you) so that others can give advice.
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]
+979.845.6754
On Mar 31, 2012, at 11:35 AM, Nick Cox wrote:
> You asked the same question yesterday and there were no answers. When
> that happens it is best to assume that the original question was not
> clear enough. Actually this version is even less informative than
> yesterday's!
>
> In this case, I see only that you want to -reshape- and that your
> attempts to do that don't satisfy. But you don't explain what most of
> these variables are. I can guess at -hhid- and -year-. Perhaps -mo-
> means "month". Why should have to guess?
>
> Nor do you show us the structure you want. What would a typical
> observation look like in the ideal structure?
>
> Nick
>
> On Sat, Mar 31, 2012 at 2:00 PM, Mintewab Bezabih
> <[email protected]> wrote:
>
>> I was trying to reshape wide my data using the command below:
>>
>>
>> egen both=group ( year mo ), label
>> egen new=group ( kebele hhid s25q3 ), label
>>
>> reshape wide mavg , i(new) j( both)
>>
>> my variables are : s25q3 hhid kebele year mo
>>
>> but while my code runs fine, I just end up with almost no observations in the reshaped file. I would appreciate any suggestion on how I could do this right
>>
>
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/