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
Coefficient InterpretationHi, I am a bit confused with coefficient interpretation. Y = b0 + b1X + e I know that if Y is 0-1…
RE: interaction of marginal effects in logit modelsHi! In logit models, I am interested in estimating the slope of a tangent line. According to Hanush…
Different Number of Observations when using 2SLS and IVprobitHi. I am examining the impact of the migration of one member on children in the migrant's household.…
Is this video correct?I am new to stata. I am trying to learn about loops. I searched youtube I found this video. Is this …
xtabond2 GMM: No Observation ErrorHi, I have an unbalanced panel comprising of data from the years 2005 and 2011. I am trying to run …
Subscribe to:
Post Comments (Atom)
0 Response to Variable Generation
Post a Comment