Statalist


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

Re: st: disregarding duplicate observations in a variable list


From   "Scott Merryman" <[email protected]>
To   [email protected]
Subject   Re: st: disregarding duplicate observations in a variable list
Date   Wed, 7 Jan 2009 07:56:32 -0600

Would it be easier to work with this data in the long form?

Here is one way:

clear
input id	emp1_97     emp2_97     emp3_97     emp1_98     emp2_98     emp3_98
1      9701            9702             9703            9801 9701             .
2      9701            .                   .                  9701      .	.
end
reshape long emp1 emp2 emp3, i(id) j(year)  string
//destring year, ignore(_) replace
reshape long emp, i(id year) j(job)
bys id emp: gen njob = _n ==1 if emp != .
by id : replace njob = sum(njob)
by id: replace njob = njob[_N]
l, sepby(id)

//return to wide format
reshape wide emp ,i(id year) j(job)
reshape wide emp* , i(id nj) j(year) string
l, sepby(id)


Scott

On Tue, Jan 6, 2009 at 8:37 PM, Jessica Looze <[email protected]> wrote:
> Hi all,
>
> I am trying to create a variable that indicates the number of jobs an
> individual has held during a period of years. The dataset I am using,
> NLSY97, records each respondents' work history in a roster format.
> This roster assigns each job a unique ID indicating the year the job
> began. For example, the roster for respondent #1 might look like:
>
> ID     Year     Job 1     Job2     Job3
> 1      1997     9701      9702    9703
> 1      1998     9801      9701    .
>
> So, during these two years, this respondent held four different jobs
> (9701 extending over into 1998).
>
> My data looks something like this:
>
> ID     EMP1_97     EMP2_97     EMP3_97     EMP1_98     EMP2_98     EMP3_98
> 1      9701            9702             9703            9801
>  9701             .
> 2      9701            .                   .                  9701
*
*   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