Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: reshape question


From   Alan Acock <[email protected]>
To   [email protected]
Subject   Re: st: reshape question
Date   Mon, 01 Feb 2010 15:34:01 -0800

Alan Acock

On Monday, February 01, 2010, at 03:22PM, "Michael Norman Mitchell" <[email protected]> wrote:
>Dear Alan
>
>  Dyad data is always crazy. Here is a solution I came up with. I don't 
>think it is elegant, but I think it does get the job done...
>
>clear
>input dyad   hr1  hr2  sr1  sr2  gr1  gr2
>1  1.2  .6  6  7  1  1
>2  4.3  2.3  5  9  -1  -1
>3  .4  .6  3  4  1  1
>4  .3  .5  6  8  1  1
>5  3.2  1  2  6  -1  -1
>6  1.1  .8  3  8  1  1
>7  2  1.5  5  7  1  1
>8  .4  1.6  7  4  -1  -1
>9  .3  .5  3  3  1  1
>10  3.2  2  5  8  1  1
>11  .8  2.1  8  5  -1  -1
>12  2.3  2.5  5  7  -1  -1
>13  1  2  4  6  1  1
>14  2.5  1.5  6  7  1  1
>15  2  .5  5  6  1  1
>16  1.8  2.6  7  4  -1  -1
>17  4.3  2  2  4  -1  -1
>18  1  2  4  4  -1  -1
>19  2.5  2.5  6  5  -1  -1
>20  1  .5  3  4  -1  -1
>end
>
>/*
>dyad person      gr  sr    hr1  hr2
>1        1        1   6    1.2   .6
>1        2       1    7     .6    1.2
>2        1       -1   5    4.3  2.3
>2        2       -1   9    2.3   4.3
>*/
>
>
>reshape long hr sr gr, i(dyad) j(person)
>save t1, replace
>
>* get hr1 info
>use t1, clear
>keep dyad person hr
>rename hr hr1
>save t2, replace
>
>* get hr2 info, by transposing row 1 and 2
>use t1, clear
>keep dyad person hr
>replace person = 3 - person
>rename hr hr2
>save t3, replace
>
>* merge them together
>use t1
>merge 1:1 dyad person using t2, gen(m1)
>merge 1:1 dyad person using t3, gen(m2)
>
>I hope that helps!
>
>Best regards,
>
>Michael N. Mitchell
>See the Stata tidbit of the week at...
>http://www.MichaelNormanMitchell.com
>Visit me on Facebook at...
>http://www.facebook.com/MichaelNormanMitchell
>
>
>Alan Acock wrote:
>> Kenney, Kashy, & Cook. Dyadic Data Analysis Has a wide dataset that 
>> looks like this:
>>
>> dyad hr1 hr2 sr1 sr2 gr1 gr2
>> 1 1.2 .6 6 7 1 1
>> 2 4.3 2.3 5 9 -1 -1
>> 3 .4 .6 3 4 1 1
>> 4 .3 .5 6 8 1 1
>> 5 3.2 1 2 6 -1 -1
>> 6 1.1 .8 3 8 1 1
>> 7 2 1.5 5 7 1 1
>> 8 .4 1.6 7 4 -1 -1
>> 9 .3 .5 3 3 1 1
>> 10 3.2 2 5 8 1 1
>> 11 .8 2.1 8 5 -1 -1
>> 12 2.3 2.5 5 7 -1 -1
>> 13 1 2 4 6 1 1
>> 14 2.5 1.5 6 7 1 1
>> 15 2 .5 5 6 1 1
>> 16 1.8 2.6 7 4 -1 -1
>> 17 4.3 2 2 4 -1 -1
>> 18 1 2 4 4 -1 -1
>> 19 2.5 2.5 6 5 -1 -1
>> 20 1 .5 3 4 -1 -1
>>
>> Where the dyads are interchangeable (same sex roomates). hr1 is time 
>> roommate arbitrarily labeled 1 works on housekeeping, hr2 is same for 
>> roommate labeled 2, sr1 is roommate's 1' satisfaction, sr2 is the 
>> partner's satisfaction, gr1 and gr2 are their genders. He wants it in 
>> a sort of long format,
>>
>> dyad person gr sr hr1 hr2
>> 1 1 1 6 1.2 .6
>> 1 2 1 7 .6 1.2
>> 2 1 -1 5 4.3 2.3
>> 2 2 -1 9 2.3 4.3
>>
>> Dyad, person, and gr and sr are in long format, but hr1 and hr2 are 
>> not. Also, in row 1 we have hr1 then hr2 as in the wide dataset, but
>> in row two we have hr2 for the first person in the hr1 column and hr1 
>> for the first person in the hr2 column.
>>
>> He then runs a SAS command
>> proc mixed covtest;
>> class dyadid;
>> model sr = hr1 hr2 / solution
>> ddfm=satterth;
>> repeated / type = cs subject = dyadid;
>>
>> I can run
>> reshape long sr gr, i(dyad) j(person)
>> but this doesn't do the hr1 the way they need them. The results show 
>> how much a person's time (actor) doing chores influences their own 
>> satisfaction and how much a partner's time doing chores influences the 
>> actor's satisfaction.
>>
>> How can I reshape the data to duplicate their result.
>>
>> Alan Acock
>>
>> *
>> * 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/
>
>
*
*   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index