capture log close log using election, replace prog drop _all infile using fl-county.dct, clear tab county gen n = gore + bush + bucha + nader gen shgore = gore/n gen shbush = bush/n gen shbuch = bucha/n *gen lngore = ln(gore) *gen lnbuch = ln(buchanan) *gen lnbush = ln(bush) *gen lnshgore = lngore - ln(n) *gen lnshbuch = lnbuch - ln(n) *gen lnshbush = lnbush - ln(n) list if county == "PALMBEACH" *buch vs. n *reg buch n *predict hat1 *generate dev1 = buch - hat1 *generate pdev1 = dev1/hat1 *list county buch hat1 dev1 pdev1 list county buch ! /bin/rm buch-n.gph buch-n.ps buch-n.eps graph buch n, c(.) s([county]) sort saving(buch-n) gphpen buch-n -dps -n !gs -sDEVICE=epswrite -sOutputFile=buch-n.eps -dBATCH -dNOPAUSE buch-n.ps *bush vs. n *reg bush n *predict hat2 *generate dev2 = bush - hat2 *generate pdev2 = dev2/hat2 *list county bush hat2 dev2 pdev2 list county bush ! /bin/rm bush-n.gph bush-n.ps bush-n.eps graph bush n, c(.) s([county]) sort saving(bush-n) gphpen bush-n -dps -n !gs -sDEVICE=epswrite -sOutputFile=bush-n.eps -dBATCH -dNOPAUSE bush-n.ps *gore vs. n *reg gore n *predict hat3 *generate dev3 = gore - hat3 *generate pdev3 = dev3/hat3 *list county gore hat3 dev3 pdev3 list county gore ! /bin/rm gore-n.gph gore-n.ps gore-n.eps graph gore n, c(.) s([county]) sort saving(gore-n) gphpen gore-n -dps -n !gs -sDEVICE=epswrite -sOutputFile=gore-n.eps -dBATCH -dNOPAUSE gore-n.ps gen lngore = ln(gore) gen lnbuch = ln(buch) gen lnshgore = ln(shgore) gen lnshbuch = ln(shbuch) *shimer reg reg lnshbuch shgore gen lnn = ln(n) *my reg1 reg lnshbuch lnshgore *my reg2 reg lnbuch shgore lnn test lnn=1 sum buch global tbuch = _result(18) di $tbuch sum n global tn = _result(18) di $tn *this is mle for phi0 global phi0 = $tbuch/$tn di $phi0 global pbbuch = 3407 global pbn = 431621 program define buch *parse "`*'", parse(" ") di "local macro is `1'" sum n local tn = _result(18) sum buch local tbuch = _result(18) local phi0 = `tbuch'/`tn' di "MLE for Phi_0 is:" _skip(8) `phi0' local pbn = 431621 clear set obs `1' gen double prob = 0 while `1' > 0 { /* looping */ replace prob = Binomial(431621,`1',`phi0') if _n == `1' local 1 = `1' - 1 } * di "Probability that Buchanan gets no more than `1' votes is" _newline _newline "`prob'" end buch 3407 gen votes = _n !/bin/rm prob-buch.gph prob-buch.ps prob-buch.eps graph prob votes, c(.) saving(prob-buch) xlab ylab(0,0.1,0.25,0.5,0.75,1.0) gphpen prob-buch -dps -n !gs -sDEVICE=epswrite -sOutputFile=prob-buch.eps -dBATCH -dNOPAUSE prob-buch.ps log close exit