I have a program pf that folks at Stata help me write to compute variations on probit and I just tried to make it byable. The original program is called pf but I changed it to be called pfnew.
If someone can tell me what I did wrong I would appreciate it.
I typed into Stata
. bys pid3: pfnew votetrumpbiden ftillegal
program pf already defined
(error occurred while loading pfnew.ado)
r(110);
after changing the program to read:
*! 1.1.0 3/17/97 MCF
program define pfnew
version 5.0
local varlist "req min(2)"
local if "opt"
local in "opt"
local options "*"
local weight "fweight aweight"
parse "`*'"
probit `*',nolog
tempvar touse
mark `touse' `if' `in' [`weight' `exp']
markout `touse' `varlist'
parse "`varlist'", parse(" ")
local depvar "`1'"
tempvar pred x1 x2
quietly {
predict `pred' if `touse'
predict `x1', in, if `touse'
qui replace `x1' = (`x1'*`x1'+1)
qui summ `x1' if `pred' ~= . [`weight' `exp']
local mzr = 1 - 1/_result(3)
qui replace `x1'=.
qui replace `x1'=0 if `pred' < .5 & `pred' ~= .
qui replace `x1'=1 if `pred' >=.5 & `pred' ~= .
qui gen `x2'=1 if `x1' == `depvar' & `pred' ~= .
qui replace `x2'=0 if `x1' ~= `depvar' & `pred' ~= .
qui summarize `x2' if `touse' [`weight' `exp']
local ppc = _result(3)
qui summarize `depvar' if `pred' ~=. [`weight' `exp']
local mnd = _result(3)
drop `x1'
egen `x1'=mean(`x2') if `pred' ~=.
qui replace `x1'=1-`x1' if `x1' < .5 & `pred' ~=.
drop `x2'
egen `x2'=mean(`depvar') if `pred' ~=.
qui replace `x2'=1-`x2' if `x2' < .5 & `pred' ~=.
summ `x2' [`weight' `exp']
local ppn=_result(3)
replace `x1'=(`x1'-`x2')/(1-`x1')
sum `x1' [`weight' `exp']
local pre=_result(3)
}
global S_1 = `mzr'
global S_2 = `ppc'
global S_3 = `mnd'
global S_4 = `x2'
global S_5 = (`x1'-`x2')/(1-`x1')
di
di in gr _col(4) " Goodness of fit measures for probit "
di in gr _col(4) "----------------------------------------------"
di in gr _col(4) "McKelvey-Zavoina R Square: " /*
*/ in ye %6.4f `mzr'
di in gr _col(4) "Proportion Predicted Correctly (Model): " /*
*/ in ye %6.4f `ppc'
di in gr _col(4) "Mean of Dependent Variable: " /*
*/ in ye %6.4f `mnd'
di in gr _col(4) "Proportion Predicted Correctly (Null): " /*
*/ in ye %6.4f `ppn'
di in gr _col(4) "Proportional Reduction in Error: " /*
*/ in ye %6.4f `pre'
end
0 Response to byable problem
Post a Comment