Dear Statalist,
I have the following dataset showing each person each day working multiple shifts. For instance, the first row means the id1 day1 shift1 lasts for 20 minutes.
I want to generate a duration lag variable showing the working duration of the previous shift of the same day (as shown by the last variable durationlag)
clear
input byte(id date shift duration durationlag)
1 1 1 20 .
1 1 1 20 .
1 2 1 30 .
1 2 2 50 30
2 1 1 60 .
2 1 1 60 .
2 1 2 70 60
2 1 2 70 60
end
[/CODE]
I treid the following code but it does not work well.
gen durationlag=.
bys id date : replace durationlag=duration[_n-1]
bys id date shift: replace durationlag=durationlag[_n-1]
Can someone give me some advice?
Thank you very much.
Best,
Changjun
Related Posts with Variable Generation
Choice of a reference category in Logistic regression analysisDear Stata listers, I ran a logistic regression model which has a factor variable Education level (…
CollinearityHi, Please see the attached. Stata has omitted two of my variables because of "collinearity". What …
Error: Repeated time values within panelHello I'm trying to make a pooled OLS regression for the years t=2 (1992 and 1999) and for the regi…
Data Envelopment Analysis Subscript invalidHello together, I am currently working on an efficiency study. For this I am using the data envelop…
Question regarding loop function.Dear Statalist members, I am trying to set up a loop function, but so far my efforts have been frui…
Subscribe to:
Post Comments (Atom)
0 Response to Variable Generation
Post a Comment