Hi everyone,
I am looking to do two things with my data that I am struggling with setting up the equation for - please advise. First, I want to estimate the total proportion (not the mean proportion) by group (of schools), year, outcome, and treatment (=0 or =1). Then, from that proportion, I would like to calculate the average for all years in that proportion.
This is my code:
generate outcome_total=.
replace outcome_total = sum(outcome) / sum(number_of_participants)
sum outcome_total if treatment==1 | year==2001
sum outcome_total if treatment==0 | year==2001
sum outcome_total if treatment==1 | year==2002
sum outcome_total if treatment==0 | year==2002
sum outcome_total if treatment==1 | year==2003
sum outcome_total if treatment==0 | year==2003
mean outcome_total if treatment==1
mean outcome_total if treatment==0
The issue I'm running into is whether I'm supposed to "sum" of "outcome_total" per year and then "mean" it to get the total average proportion? I wanted to get the aggregate of outcome by treatment and year and then the mean of all the years. But without the "sum" per year, I get different numbers for the different schools in each year because I don't know how to group the schools together. I would appreciate any help in grouping the schools by year, outcome, treatment and getting the aggregate of that and then take the mean by total years. Please let me know if that makes sense. Many thanks!
This is my dataset:
clear
input float(year school treatment outcome number_of_participants)
6 1 1 1
7 1 1 1
8 1 1 1
9 1 1 1
10 1 1 1
6 1 1 1
7 1 1 1
8 1 1 1
9 1 1 1
10 1 1 1
6 1 1 1
7 1 1 1
8 1 1 1
9 1 1 1
10 1 1 1
1 1 164 183
2 1 195 203
3 1 208 214
4 1 314 209
5 1 247 195
6 1 57 71
7 1 51 87
8 1 47 57
9 1 36 23
Related Posts with Aggregating variable by year and proportions
Restricting data of patient ID to perform 1 test at a time rather than all of themGood Afternoon, If anyone could give me advice I would really appreciate that. I know it is going t…
Problem with individual ID when importing an excel sheet to stataHi. I have an excel sheet that includes individual ID variable. Whenever I import the excel sheet to…
maximum command in stata> Dear Sir or Madam, > > I tried to use ml maximize command in Stata. > But I receive…
Generating a Financial Inclusion IndexHello everyone, I am in dire need of your help, I am trying to generate a Financial inclusion index …
access to the full set of parameters of one single equationDear Statalist, I have a simple question regarding how to get access to the full set of parameters …
Subscribe to:
Post Comments (Atom)
0 Response to Aggregating variable by year and proportions
Post a Comment