Hello,
I'm new to Stata and have to admit that I am struggling with its programming capabilities. The image attached displays a chunk of my dataset. I have employment records for individuals (pid) by year (syear). The variable pgjobch monitors whether these individuals have switched jobs or not.
What I would like to do is that if for any pid the pgjobch variable does not contain "first job" (code 5), ALL records for countjobs2 and tenuresum2 are replaced with missing.
My problem is that I don't know how to check for all syear and then set all records to missing
I have tried this
bysort pgjobch (pid): gen keep = 1 if pgjobch[_N] == 5
But that only sets the last variable to 1, not all of them.
I'm new to Stata and have to admit that I am struggling with its programming capabilities. The image attached displays a chunk of my dataset. I have employment records for individuals (pid) by year (syear). The variable pgjobch monitors whether these individuals have switched jobs or not.
What I would like to do is that if for any pid the pgjobch variable does not contain "first job" (code 5), ALL records for countjobs2 and tenuresum2 are replaced with missing.
My problem is that I don't know how to check for all syear and then set all records to missing
I have tried this
bysort pgjobch (pid): gen keep = 1 if pgjobch[_N] == 5
But that only sets the last variable to 1, not all of them.
Comment