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
Related Posts with byable problem
Percentage of a variable depending on different income binsI'm trying to find out depending on the variation of income what percentage of a particular income b…
Is this correct for converting daily into weekly returns?Dear All I want to convert daily market returns into weekly market returns. The weeks are defined i…
comparing two linear regression linesI am comparing the glomerular filtration rate (continuous) measured by creatinine clearance (gold st…
Deleting number of observations below 3 in histogram?Hi, How can I delete the bars in the histogram if there is less or equal to 3 observations? The his…
Strange error of function usubinstr???Hi! I want to use the function usubinstr() to replace unicode substring "我爱" in Unicode string varia…
Subscribe to:
Post Comments (Atom)
0 Response to byable problem
Post a Comment