Hi all,
I'm stuck with an apparently simple problem of finding average year-on-year change in a variable of interest. The average I got is wildly off and I suspect I have made a mistake in the code. I describe below a sample data and my result.
I'm trying to find the percentage of pupils who move schools from one year to the other. I did the following
I suspect this is wrong because I'm getting absurdly high numbers in my original data. I think I might be misunderstanding the concept/coding it incorrectly.
Appreciate any help.
Thanks!
I'm stuck with an apparently simple problem of finding average year-on-year change in a variable of interest. The average I got is wildly off and I suspect I have made a mistake in the code. I describe below a sample data and my result.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input str3 id float(year school) "111" 2011 221 "111" 2012 222 "111" 2013 221 "112" 2011 222 "112" 2012 221 "112" 2013 224 "113" 2011 224 "113" 2012 222 "113" 2013 222 "114" 2011 222 "114" 2012 221 "114" 2013 224 end
Code:
sort id year by id (year): g move_school=0 if _n>1 by id (year): replace move_school=1 if school !=school[_n-1] & !missing(school) & !missing(school[_n-1]) gcollapse(max) pupilmoved= move_school,by(id) merge
Code:
sort year by year: egen annualmove=mean(pupilmoved) tab annualmove year tab annualmove year,col nofreq
Appreciate any help.
Thanks!
Comment