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: spell to person/month


From   Doerthe Gatermann <[email protected]>
To   [email protected]
Subject   st: spell to person/month
Date   Mon, 07 Nov 2011 19:04:28 +0100

Dear all,

i have a spell-file and I want to have a panel-file. I could use the –expand– command and do something like this:

gen length = (end – start) + 1
expand length
bysort persnr (n_job) : gen month = _n


But this causes some difficulties, because in my spellfile there are people with more than one job at the same time. When I use –expand- as shown above I produce too many rows. The second problem is: I need to generate new colums (dummy variables) to store the information of the beginning/end of first an second job and overlaps – please see illustration.

The spell-file:

persnr   spell  startmonth endmonth
 1       school    400       450
 1       job       451       460
 1       job       455       500


The person/month file I want to have:

pernr month school_1 job_1 job_2
  1    400     1      0     0
  1    401     1      0     0
  .
  .
  1    451     0      1     0
  1    452     0      1     0
  .
  .
  1    455     0      1     1
  1    456     0      1     1

Using –reshape wide– first (to get one row for one person) and then
–expand– is one way to get the datastructure I want, but it is laborius. Does anybody know a better way?


Thanks! Dorthe



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