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
Reducing space between columns using frmttableHi. I'm trying to fit a multicolumn table in word using the stata command "frmttable". The spacing b…
How to generate Hosmer Lemeshow test/ goodness of fit in the case of xtlogit, re?Hi, After conducting xtlogit, re (logistic regression for panel data), how do I check the goodness …
Anova problemDear Statalisters, I haven't done anova in Stata since the advent of great 'xt/mixed'. But for part…
Generate population data based on known population characteristicsHello everyone, My goal is to draw a random sample from a population of registered voters. However,…
min, max, mean of correlaiton matrixI apologize if I've overlooked something, but I cannot find an answer. For simplicity, I'll use an e…
Subscribe to:
Post Comments (Atom)
0 Response to Variable Generation
Post a Comment