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
re-formulate a functionHello everyone, I have this equation Code: g=exp(1.546776)*(x/(1-x)^(0.4314782)*y^(1-0.4314782)-exp…
Graphing Medians Panel DataHello, I'd like to graph the median values of a variable. The data I have looks like this, and I wou…
Interpreting stata output with log dependent variable and % independent variablesHello stata users, Hope you are doing well. I have a question regarding interpreting stata output i…
Struggling with -mkspline-I'm struggling on interpreting the output after using the mkspline command. I have a continuous exp…
Inlcude industry- and year-fixed effects in regressionHello, I want to do a regression with one dependent variable and an independent variable and a few …
Subscribe to:
Post Comments (Atom)
0 Response to Create a variable with an increasing value for different groups
Post a Comment