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?
Unequal interval systematic samplingI can easily do systematic sampling from the equal interval sample like 1,2,3,4,5,6,7,8,9,........ B…
How to calculate percentage of certain categories using bysort command?I have a dataset at the individual level which includes a variable on education. The variable takes …
delete observations according to some rulesDear statalist, I have two sets of data and I append them together. The first set consists of a ser…
Penalized spline models with -mixed-Greetings, all. I recently ran across a StataCorp presentation by Roberto Gutierrez that discussed …
Loop over variablesinput double(month202001 month202002 month202003 month202004 month202005 month202101 month202102 mon…
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