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
0 Response to Create a variable with an increasing value for different groups
Post a Comment