set more 1
insheet using mgp.csv, clear
sort school_name
g o=_n             
g N11=min(n_fay_students_reading_2011,n_fay_students_math_2011)
g N12=min(n_fay_students_reading_2012,n_fay_students_math_2012)
g N=min(N11,N12)
su N11, d
g LowN11=N11<=r(p25) if N11<.
g MidN11=N11>r(p25) & N11<r(p75) if N11<.
g HigN11=N11>=r(p75) if N11<.
g LowN12=N12<=r(p25) if N12<.
g MidN12=N12>r(p25) & N12<r(p75) if N12<.
g HigN12=N12>=r(p75) if N12<.
expand 3
bys o: g x=_n     
g x2=cond(x==1,mgp_lowerlimit_reading_2012,mgp_upperlimit_reading_2012 ) if x<3
g x1=cond(x==1,mgp_lowerlimit_reading_2011,mgp_upperlimit_reading_2011 ) if x<3
cap mkdir ex2
loc i 1
file close _all
file open s`i' using ex2/s`i'.html, write replace 
file write s`i' `"<html><head><title>School Quality</title>"'
file write s`i' _n `"<script type='text/javascript'>//<![CDATA[                       "'
file write s`i' _n `"window.onload=function(){                                        "'
file write s`i' _n `"var select = getElementsByClassName(document.body,'mod_select'); "'
file write s`i' _n `"for (var i= 0; i < select.length; i++){                          "'
file write s`i' _n `"     select[i].onchange = function() {                           "'
file write s`i' _n `"       var prevSibling = this.previousSibling;                   "'
file write s`i' _n `"       while(prevSibling && prevSibling.className != 'image') {  "'
file write s`i' _n `"            prevSibling = prevSibling.previousSibling;           "'
file write s`i' _n `"        }                                                        "'
file write s`i' _n `"       prevSibling.src = this.value;                             "'
file write s`i' _n `"     }                                                           "'
file write s`i' _n `"}                                                                "'
file write s`i' _n `"function getElementsByClassName(node, classname) {               "'
file write s`i' _n `"    var a = [];                                                  "'
file write s`i' _n `"    var re = new RegExp('(^| )'+classname+'( |$)');              "'
file write s`i' _n `"    var els = node.getElementsByTagName('*');                    "'
file write s`i' _n `"    for(var i=0,j=els.length; i<j; i++)                          "'
file write s`i' _n `"        if(re.test(els[i].className))a.push(els[i]);             "'
file write s`i' _n `"    return a;                                                    "'
file write s`i' _n `"}                                                                "'
file write s`i' _n `"}//]]>                                                           "'
file write s`i' _n `"</script>                                                        "'
file write s`i' _n `"</head><body bgcolor="#909eab"><center><p><table bgcolor="#FFFFFF" width=800><tr><td>"'
file write s`i' _n `"<p>Public schools in DC have <a href="http://dcps.dc.gov/DCPS/Files/downloads/ABOUT%20DCPS/FINAL%202013%20DC%20NAEP%20Results%20One-Pager%5B1%5D.pdf">gained ground on national tests</a> over the <a href="http://jaypgreene.com/2012/01/12/a-closer-look-at-dc-naep-scores/">last 15 years</a>,"'
file write s`i' _n `"but much of that gain is due to the changing demographic composition of DC's student body. The income and education of parents is one of the primary determinants of student performance, and as DC residents have gotten better-off, so have incoming students' scores. Comparing NAEP scores over time without accounting"'
file write s`i' _n `"for incoming class scores is mere <a href="http://greatergreatereducation.org/post/18672/bad-advocacy-research-abounds-on-school-reform/">jackaNAEPery</a>, and comparing proficiency levels is no better.</p>"'
file write s`i' _n `"<p>The best measure of school quality is how much students learn: their improvement from incoming to outgoing scores, not how well they test at just one point in time."'
file write s`i' _n `"<a href="http://www.urban.org/publications/411290.html">Measuring how much students learn over time is difficult</a>, and both teacher impact evaluations and school-specific test score growth measures compare only how well students in DC "'
file write s`i' _n `"public schools do relative to other students in DC public schools. This leads to relative rankings only, not measures of how DC public schools as a whole are improving.</p>"'
file write s`i' _n `"<p>The <a href="http://osse.dc.gov/sites/default/files/dc/sites/osse/release_content/attachments/DC%20Schoolwide%20Growth%20Data%20Report_0.pdf">median growth percentile (MGP)</a>  can give us an idea of how much a given school improves students' scores relative to other schools (relativism is characteristic of <a href="http://www.caldercenter.org/publications/upload/WP-80_2.pdf">other measures of value added by schools</a> as well). Each student's growth percentile score is equal to the percentage of comparable students district-wide who performed worse on a later math and reading exam. The school's score is then the typical student's score."'
file write s`i' _n `"</p><p>The main problem is that these scores are fraught with measurement error, so rarely can we say with confidence that one school is better than another school. For example, Bancroft was in the top third on math MGP for 2011-12 and H.D. Cooke was in the bottom third, but the two math MGP scores are statistically indistinguishable (the margins of error overlap)."'                                                                                                                                                                                                                                                                                                                                                   
file write s`i' _n `"</p><p>The graph below shows each school's math versus reading MGP scores for 2011 and 2012. A box around each dot indicates the range of statistically indistinguishable values for both math and reading in that year (2013 data were not released with the ranges). This way, we can compare the score both to other schools and to the typical school with a score of 50 (whose dot would be at the intersection of the math and reading lines at 50). Each school's box overlaps with the boxes of many other schools, and any two schools whose boxes touch are statistically indistinguishable. Whenever we compare schools, we should remain appropriately skeptical about the relative strengths of signal and noise in these data.</p>"'
file write s`i' _n `"<center><img class="image" src="sch`i'.png" alt="One school's scores shown compared to all other schools" width="600"/>"'
file write s`i' _n `"<br><select class="mod_select">"'
forv j=1/177 {
 su lea_c if o==`j', mean
 loc sys=cond(r(mean)==1, "DCPS", "Charter")
 qui levelsof school_name if o==`j', loc(s)     
 loc ss:di `s'
 if `i'==`j' file write s`i' _n `"<option SELECTED value="sch`j'.png">`ss' (`sys')</option>"'
 if `i'!=`j' file write s`i' _n `"<option value="sch`j'.png">`ss' (`sys')</option>"'
 }
file write s`i' _n `"</select>"'
file write s`i' _n `"</center><p>So what <em>can</em> we say? Charter schools (in blue) tend to have higher growth scores, but traditional public schools are overrepresented at both the highest and lowest ranks. The main difference between the sectors is that charters tend not"'
file write s`i' _n `"to be observed among the lowest performing schools, suggesting that <a href="http://www.urban.org/publications/1001499.html">the worst charters are better than the worst traditional public schools</a>.</p>"'
file write s`i' _n `"<p>But there are surprises in both sectors. For example, what is the best high school in town? Ranked by the MGP for math, it is <a href="http://www.thurgoodmarshallacademy.org/about">Thurgood Marshall Academy</a>"'
file write s`i' _n `"(Charter), east of the Anacostia, with <a href="http://profiles.dcps.dc.gov/McKinley+Technology+High+School">McKinley Technical High School</a> (DCPS) in Eckington running"'
file write s`i' _n `"a close second. Only a handful of other high schools are statistically better than average on math in both years, but the sought-after high schools Woodrow Wilson and School Without Walls are not on that list.</p>"'
file write s`i' _n `"<p>Among elementary schools, the top performers are scattered around the city, for example Ross in <span class=SpellE>Dupont</span>, Stanton in far Southeast DC, Tubman in Columbia Heights, Watkins on Capitol Hill, and Stoddert in Glover Park."'
file write s`i' _n `"The top middle schools are the KIPP DC AIM and KEY Academies, with Cesar Chavez Prep and D.C. Prep Edgewood Middle charters not far behind. The highly regarded Deal Middle School barely squeaks out a statistical advantage over the typical school.</p>"'
file write s`i' `"</td></tr></table></body></html>"'   
file close _all
forv i=1/177 {
 tw rarea mgp_upperlimit_math_2012 mgp_lowerlimit_math_2012 x2 if o!=`i', cmiss(n) fc(none) fin(100) lcol(gs15) lw(vvthin)||sc mgp_math_2012 mgp_reading_2012 if lea_c==1& o!=`i' &LowN12==1, msize(small) mcol(gs6)||sc mgp_math_2012 mgp_reading_2012 if lea_c==1& o!=`i'&MidN12==1, msize(medium) mcol(gs5)||sc mgp_math_2012 mgp_reading_2012 if lea_c==1& o!=`i'&HigN12==1, msize(medlarge) mcol(gs5)||sc mgp_math_2012 mgp_reading_2012 if lea_c!=1& o!=`i'&LowN12==1, msize(small) mcol(ebblue)||sc mgp_math_2012 mgp_reading_2012 if lea_c!=1& o!=`i'&MidN12==1, msize(medium) mcol(ebblue)||sc mgp_math_2012 mgp_reading_2012 if lea_c!=1& o!=`i'&HigN12==1, msize(medlarge) mcol(ebblue)||rarea mgp_upperlimit_math_2012 mgp_lowerlimit_math_2012 x2 if o==`i', fc(none) fin(60) lcol(orange) lw(medthick) cmiss(n)||sc mgp_math_2012 mgp_reading_2012 if o==`i' &LowN12==1, mcol(orange) msize(small) ||sc mgp_math_2012 mgp_reading_2012 if o==`i' &MidN12==1, mcol(orange) msize(medium)||sc mgp_math_2012 mgp_reading_2012 if o==`i' &HigN12==1, mcol(orange) msize(medlarge) leg(off) name(y2o`i', replace) title("{bf:2012}",  tsty(heading)) graphr(fc(white)) xla(0(10)100, nogrid) yla(0(10)100, nogrid) xti(" " "Reading",  tsty(heading)) yti(" " "Math",  tsty(heading)) || function y=50, ra(0 100) lcol(black) lw(vthin) || function 50000*(x-49.999), ra(49.999 50.001) lcol(gs6) lw(vthin) ysc(noline) xsc(noline) plotr(margin(zero) ilw(none) lsty(grid))
 tw rarea mgp_upperlimit_math_2011 mgp_lowerlimit_math_2011 x1 if o!=`i', cmiss(n) fc(none) fin(100) lcol(gs15) lw(vvthin)||sc mgp_math_2011 mgp_reading_2011 if lea_c==1& o!=`i' &LowN11==1, msize(small) mcol(gs6)||sc mgp_math_2011 mgp_reading_2011 if lea_c==1& o!=`i'&MidN11==1, msize(medium) mcol(gs5)||sc mgp_math_2011 mgp_reading_2011 if lea_c==1& o!=`i'&HigN11==1, msize(medlarge) mcol(gs5)||sc mgp_math_2011 mgp_reading_2011 if lea_c!=1& o!=`i'&LowN11==1, msize(small) mcol(ebblue)||sc mgp_math_2011 mgp_reading_2011 if lea_c!=1& o!=`i'&MidN11==1, msize(medium) mcol(ebblue)||sc mgp_math_2011 mgp_reading_2011 if lea_c!=1& o!=`i'&HigN11==1, msize(medlarge) mcol(ebblue)||rarea mgp_upperlimit_math_2011 mgp_lowerlimit_math_2011 x1 if o==`i', fc(none) fin(60) lcol(orange) lw(medthick) cmiss(n)||sc mgp_math_2011 mgp_reading_2011 if o==`i' &LowN11==1, mcol(orange) msize(small) ||sc mgp_math_2011 mgp_reading_2011 if o==`i' &MidN11==1, mcol(orange) msize(medium)||sc mgp_math_2011 mgp_reading_2011 if o==`i' &HigN11==1, mcol(orange) msize(medlarge) leg(off) name(y1o`i', replace) title("{bf:2011}",  tsty(heading)) graphr(fc(white)) xla(0(10)100, nogrid) yla(0(10)100, nogrid) xti(" " "Reading",  tsty(heading)) yti(" " "Math",  tsty(heading)) || function y=50, ra(0 100) lcol(black) lw(vthin) || function 50000*(x-49.999), ra(49.999 50.001) lcol(gs6) lw(vthin) ysc(noline) xsc(noline) plotr(margin(zero) ilw(none) lsty(grid))
 su lea_c if o==`i', mean
 loc sys=cond(r(mean)==1, "DCPS", "Charter")
 levelsof school_name if o==`i', loc(t)     
 loc tt:di `t'
 gr combine y1o`i' y2o`i', ycommon xcommon title(`"{bf:`tt' (`sys') highlighted in orange}"', pos(11) just(left) col(edkblue)) name(o`i', replace) graphr(fc(gs15)) xsize(8) ysize(4) graphr(fc(white)) 
 gr export ex2/sch`i'.png, replace width(1200) height(600)
 discard
 }
exit

