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?
Calculate the rolling standard deviation for only even yearsDear all, We are stuck with a problem regarding the calculation of rolling averages only for even f…
Problem with Forest plot using midasHi everyone, I am using midas to do diagnostic accuracy meta-analysis. I have one relatively simple…
Distribution of FEHello everyone. I am trying to get the distribution of firm fixed effects (acquirer FE) when I also…
runiform function and r(N) scalarHi, I am trying to use the runiform function to randomally select 1/3 of the observations. Unfortun…
Models that allows quantitative and qualitative variablesIn a rural household’s survey, I am working with Diff. I have work with dummies for some topics such…
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