Bookmark and Share

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: cross grouping a family w siblings and stepsiblings


From   Joerg Luedicke <[email protected]>
To   [email protected]
Subject   Re: st: cross grouping a family w siblings and stepsiblings
Date   Mon, 2 May 2011 10:23:52 -0400

On Mon, May 2, 2011 at 10:04 AM, Tinne Steffensen <[email protected]> wrote:

> Instead I will try to go back to the datasets prior to merging;
> It looks like this, where group_m is (by m_id, sort: gen group_m = _n).
>
> m_Id    child_id    gender    group_m                                  birth        handicap
>
> 1               24            2                    1                  01jan07         1
> 1               12            2                    2                  02feb08         0
> 2               47            1                    1                  10jun02         0
> 3               10            2                    1                  02apr00         0
> 4                8            2                    1                  18dec09         1
> 4               18            1                    2                  11nov02         1
> 4               56            1                    3                  18may99         0
> 5               82            1                    1                  23jun08         0
> 6               12            2                    1                  30jul01         0
>
> I want it to come out like below.
>
>   m_Id    child_id1  child_id2    child_id3   birth1      birth2        birth3
>
> 1             24        12            .        01jan07    02feb08         .
> 2             47         .            .        10jun02          .         .
> 3             10         .            .        02apr00          .         .
> 4              8        18           56        18dec09    11nov02     18may99
> 5             82         .            .        23jun08          .         .
> 6             12         .            .        30jul01          .         .
>
> I tried reshaping:
> reshape wide child_id, i(m_id) j(gr_m)
>
> But it comes up with this error-message:
> (note: j = 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
> Birth not constant within m_id

Since birthdate is something you want to reshape, too, you need to put
it into the reshape command line as well. Consider the following for
the data you posted:


//Example

/*Getting data*/
clear all
input m_Id    child_id    gender    group_m
str7       birth        handicap

1               24            2                    1
01jan07         1
1               12            2                    2
02feb08         0
2               47            1                    1
10jun02         0
3               10            2                    1
02apr00         0
4                8            2                    1
18dec09         1
4               18            1                    2
11nov02         1
4               56            1                    3
18may99         0
5               82            1                    1
23jun08         0
6               12            2                    1
30jul01         0
end

/*Reshape*/
reshape wide child_id gender birth handicap, i(m_Id) j( group_m)

//End example

That should do what you want.

J.

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index