Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: From spell to person-month file


From   n j cox <[email protected]>
To   [email protected]
Subject   RE: st: From spell to person-month file
Date   Wed, 29 Mar 2006 11:42:48 +0100

I was working to reproduce your example.

If your example is not realistic, then you
need to take the principles explained and adapt them
to your problem. For example,

gen length = end - beg + 1
expand length
bysort Persnr beg: gen month = beg[1] + _n - 1
drop length

Anna Manzoni

Subject: RE: st: From spell to person-month file
Date: Wed, 29 Mar 2006 12:19:13 +0200

Next Article (by Date): Re: st: Spatial lag models n j cox
Previous Article (by Date): Re: st: From spell to person-month file Ronnie Babigumira
Top of Thread: st: From spell to person-month file "A. Manzoni"
Articles sorted by: [Date] [Author] [Subject]


--------------------------------------------------------------------------------

Thanks to both Nick and Ronnie.
But, if the month is not always starting from one (actually it is hardly
ever, and the first month is different for every person), isn't it a problem
with this syntax?
And the fact that in many month n_job is missing?

Anna

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Ronnie Babigumira
Sent: woensdag 29 maart 2006 12:14
To: [email protected]
Subject: Re: st: From spell to person-month file

Thanks Nick

My gut feeling was that there was neater and cleverer way of doing this so I
hesitated to a response. However since I
had been bugging Anna to provide an illustration I decided to offer my
rather longish take.

Im glad I did because I have learn't something new (and in the process I
have moved a step closer to being a bi-pilot)

Ronnie

n j cox wrote:
> This is the merge-Meisters versus the by-pilots all
> over again.
>
> That is, some people set this kind of thing up as a dance
> of the files, with elaborate pas de deux fit for Fonteyn
> and Nureyev in their prime;
>
> others prefer to do it less balletically in place.
>
> I'm a by-pilot. To get from this
>
> Persnr n_job beg end sect
> 1 1 1 3 1
> 1 2 4 7 3
> 1 3 8 10 2
>
> to this
>
> Persnr month n_job sect
> 1 1 1 1
> 1 2 1 1
> 1 3 1 1
> 1 4 2 3
> 1 5 2 3
> 1 6 2 3
> 1 7 2 3
> 1 8 3 2
> 1 9 3 2
> 1 10 3 2
>
> I would go
>
> gen length = end - beg + 1
> expand length
> bysort persnr (n_job) : gen month = _n
> drop length
>
> Nick
> [email protected]
>
> Ronnie Babigumira
> =================
>
> Now we are talking (the illustration helps). Another shot (the number of
> lines will probably be cut in half). Assume you have two files, person
> and spell
>
> use person, clear
> egen beg = min(month), by(Persnr n_job)
> egen end = max(month), by(Persnr n_job)
> sort Persnr n_job beg end
> save tempa, replace
>
> use spell, clear
> sort Persnr n_job beg end
> merge Persnr n_job beg end using tempa
> drop beg end _merge
> move month n_job
> sort Persnr month
> list
>
> Anna Manzoni
> ============
>
> No, I have added to the spell file information related to the
> characteristics of the job (I could add them only to the spell file, and
not
> directly to the person month), so now, in my spell file I have a variable
> saying for example the sector in which someone was employed. I now want
> to go back to the person month file keeping also this info on the
> sector, so I have for every month in which a spell was hold, the sector
> variable.
> So illustrating>
> The first original person month file was
>
> Persnr month n_job
> 1 1 1
> 1 2 1
> 1 3 1
> 1 4 2
> 1 5 2
> 1 6 2
> 1 7 2
> 1 8 3
> 1 9 3
> 1 10 3
>
> The spell file I have generated is
>
> Persnr n_job beg end
> 1 1 1 3
> 1 2 4 7
> 1 3 8 10
>
>
> Thenn I have added the sector variable, so it looks like
> Persnr n_job beg end sect
> 1 1 1 3 1
> 1 2 4 7 3
> 1 3 8 10 2
>
> And now I want a person month likethis:
>
>
> Persnr month n_job sect
> 1 1 1 1
> 1 2 1 1
> 1 3 1 1
> 1 4 2 3
> 1 5 2 3
> 1 6 2 3
> 1 7 2 3
> 1 8 3 2
> 1 9 3 2
> 1 10 3 2
>
>
> *
> * For searches and help try:
> * http://www.stata.com/support/faqs/res/findit.html
> * http://www.stata.com/support/statalist/faq
> * http://www.ats.ucla.edu/stat/stata/
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/



*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/

--------------------------------------------------------------------------------

Next Article (by Date): Re: st: Spatial lag models n j cox
Previous Article (by Date): Re: st: From spell to person-month file Ronnie Babigumira
Top of Thread: st: From spell to person-month file "A. Manzoni"
Articles sorted by: [Date] [Author] [Subject]


--------------------------------------------------------------------------------

Go to Harvard School of Public Health LWGate Home Page.

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* 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