The long format dataset is presented as follows.
It has 3 columns,
gender (male=1; female=2),
period (1=elementary school;2=middle school;3=high school);
pat=average physical activtiy time per day.
Now, I want to use Stata code to create a new column daily_pat,
which should be equal to the running sum of pat by gender and period.
Thank you for your help!
* Example generated by -dataex-.
clear
input byte (gender period pat)
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
Related Posts with Ask for Help with Computation of Running Sum of a Variable within Multiple Variables in Stata.
Difference between sreweight and survwgt rakeHello to everyone, I was using sreweight as a reweighting command for one of my do files, when my c…
Should I use Cox PH regression when there is large share of observations that never 'die'?I'm considering model patent right transfer as a survival process. That is, when a patent is transfe…
Using a loop to rename variable label that has distinct symbolsHi Statalist community, I am using the voter.dta dataset as an example. I am using the tabulate com…
How to create a balance plot after weighting manually?I created weights for a difference-in-difference model and want to compare the correlations of the c…
Questions on computing the marginal effects of the factor variableDear all, I am wondering how to compute the marginal effects of a factor variable if the number of o…
Subscribe to:
Post Comments (Atom)
0 Response to Ask for Help with Computation of Running Sum of a Variable within Multiple Variables in Stata.
Post a Comment