Dear all,
I am using Stata version 14.2.
I have a data set with groups of products and dates of weeks for each group, and a dummy variable which determines whether an observation is after a certain date, which is different for each group.
I've created a variable which contains the date of the observation if it is after the deciding date, and 0 otherwise.
I want to create a variable which increases in value for each week which is after the deciding date of each group.
I have tried different approaches unsuccessfully, such as loops, counters, and egen (which doesn't work as I need the count to begin anew for each group)
this is an example of the data I have:
group week deciding_date after
1 1.1.19 6.1.19 0
1 8.1.19 6.1.19 8.1.19
1 15.1.19 6.1.19 15.1.19
2 1.11.18 3.11.18 0
2 8.11.18 3.11.18 8.11.18
2 15.11.18 3.11.18 15.11.18
I want to add a counter variable which would do this:
group week deciding_date after counter
1 1.1.19 6.1.19 0 0
1 8.1.19 6.1.19 8.1.19 1
1 15.1.19 6.1.19 15.1.19 2
2 1.11.18 3.11.18 0 0
2 8.11.18 3.11.18 8.11.18 1
2 15.11.18 3.11.18 15.11.18 2
I'd appreciate any help you could provide
Related Posts with Create a variable with an increasing value for different groups
How to take individuals for which info is available in both waves only?Hi, I am working with BHPS dataset. I have appended Waves 9 & 10 and have declared it as panel. …
Why does teffects psmatch number of observations not match number of treated + number of controls with 1 match per treated?My data have 200 treated units and 9,800 untreated units. When I run teffects psmatch using default …
IVprobit with 2 endogenous regressorsDear all, I have a regression with binary outcomes and two endogenous continuous regressors. When I…
Calibration Plot - Cox PH ModelHello, I would like to create a calibration plot of my cox proportional hazard model. I ran goodnes…
collapse or Roger Newman's xcollapse with string variablesTried help (and the help for xcollapse) but can't get an answer that makes sense to me. I have three…
Subscribe to:
Post Comments (Atom)
0 Response to Create a variable with an increasing value for different groups
Post a Comment