Dear Statalist,

I have a panel data for educational institutions and I need to write a code for the change in the share of secondary education institutions and share of children in secondary education between the pre (1999-2002) and post (2003-2011) treatment period. I have data on three (3) types of secondary institutions, the number of children in each of the secondary education institutions, as well as the education district and year. Please see an example of the data below:


* Example generated by -dataex
clear
edu_district nu_inst_ch nu_stud_ch nu_inst_sec nu_stud_sec nu_inst_prim nu_stud_prim year
"R1" 1 156 2 391 4 1029 1
"R1" 1 179 2 410 39 1089 2
"R1" 1 205 2 401 39 1087 3
"R1" 1 182 2 475 40 1207 4
"R1" 1 234 2 536 40 1190 5
"R1" 1 108 2 815 40 1236 6
"R1" 1 287 2 861 40 1196 7
"R1" 1 305 2 1104 40 1162 8
"R1" 1 305 2 1056 39 1098 9
"R1" 1 462 2 1036 38 1085 10
"R1" 1 581 2 1234 37 1258 11
"R1" 0 0 3 1923 31 1455 12
I have tried to generate the share by using one of the institutions, i.e., gen sec. Using this code
egen insti_total = total(numofinst_gen_sec), by (educationdistrict,year)
gen share_inst =numofinst_gen_sec/insti_total
but I am getting an error. Although, I am not sure if this is correct, given the question asked above. Thanks for your assistance and/or suggestions.


Regards