I have a small long format dataset below.
* Example generated by -dataex-. For more info, type help dataex
clear
input byte (gender period pr)
1 1 11
1 1 11
1 1 11
1 2 15
1 2 15
1 2 15
2 1 11
2 1 11
2 1 11
2 2 12
2 2 12
2 2 12
end
I want to create a new variable sum_pr,
which equals to the sum of the first value within gender and period like below:
* Example generated by -dataex-. For more info, type help dataex
clear
input byte (gender period pr sum_pr)
1 1 11 26
1 1 11 26
1 1 11 26
1 2 15 26
1 2 15 26
1 2 15 26
2 1 11 23
2 1 11 23
2 1 11 23
2 2 12 23
2 2 12 23
2 2 12 23
end
How can I use Stata code to achieve it?
Thank you!
Related Posts with How to compute the sum of the first occurence within Group(s) in Stata?
Control variables and fixed effectsHello all, I have a set of panel data for 15 countries over 10 years and I have included 5 control …
How to generate a variable with the total number per year only?Good day all, I have a dataset with 3 variables: (survival status "survived/died", year, number of …
Difficulties in invoking python in stata 16I am trying to call python into the stata 16 environment but having the below error. Any help would …
is this a correct way to rescale a variable?Hi all, I have an independent variable in my regression that lies between .0000869 and .0610705. It…
Creating an indexHey I want to create an index out of 10 variables, each of them has values on a scale from 1 to 5. I…
Subscribe to:
Post Comments (Atom)
0 Response to How to compute the sum of the first occurence within Group(s) in Stata?
Post a Comment