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]

st: reshaping to wide format, and need to create a "j" variable


From   Kendra Lewis <[email protected]>
To   [email protected]
Subject   st: reshaping to wide format, and need to create a "j" variable
Date   Tue, 25 Oct 2011 14:03:42 -0700

Dear all,

I have data that tracks foster children's transitions and placements.
The data is in long format, such that children have the same ID
variable over time, but their ID variable appears in several different
rows. Each time their ID variable appears indicates a move or
transition. Here is an example dataset:

id           placement     date of placement    age at placement
1              1                  6.7.2009                       14
1              2                  8.2.2010                       15
1              3                  2.3.2011                       15
1              1                  3.4.2011                       15
2              1                  5.4.2009                       12
3              1                  4.6.2009                       13
3              2                  7.8.2010                       14
4              1                  4.5.2009                       10
4              2                  6.7.2009                       10
4              3                  5.2.2010                       11
4              2                  7.8.2010                       11
4              3                  9.9.2010                       12
4              1                  1.4.2011                       12
5              1                  7.8.2009                       13
5              2                  6.4.2010                       14

So, id #1 has had 4 placements, #2 has only had 1, #3 as had 2, and so
on. The data needs to be put into wide format to merge in other
datasets of a similar format. I know the necessary command will be
reshape wide stub, i(id) j(??)
where stub will be the varlist-as there is no common stub in the
dataset. What I need is a "j" variable that indicates a count of the
number of times the id number appears. For example, the count for id
#1 is 4, for id #2 is 1, for id #3 is 2, for id #4 is 6, and for id #5
is 2. Then I can use this for the reshape command to be my "j"
variable.
Does anyone have any suggestions? I've spoken to a few people and we
think it may be some sort of "foreach" loop command but we are not
sure.

Thanks!

Kendra

*
*   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