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?
ppml cluster - Gravity on product level with only one importerDear all I am evaluating the effect on american imports of the trade war dispute between China and …
Making predictions on spatial panel dataHello! I am trying to make a model for estimating the demand for city-bikes. For this, I have creat…
Loop to create new variablesHello, I have data with a date variable and some other variables. For each date, there are multiple…
Test of difference between meansHi, I have data where I have compared the means and from visualising it I can see that one group ha…
Subgroup analysis in stcoxDear Statalisters, In this first post on Statlist I apologize in advance if the format or details a…
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