Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: retrieving beta coeffs


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: retrieving beta coeffs
Date   Mon, 12 Jan 2004 11:35:20 -0500

Richard suggested

does anyone know how to access the beta coeffients after regress, beta. I know how to access the standard coefficients, but not the beta coefficients. Thanks, Eric Neumayer

Dr. Eric Neumayer

One clunky way is to standardize the variables first and then run the regression with or without the noconstant option, e.g.

. egen zincome = std(income)
. egen zeduc = std(educ)
. egen zjobexp = std(jobexp)
. egen zblack = std(black)
. quietly reg zincome zeduc zjobexp zblack, noconstant
. mat list e(b)
A slightly less clunky way is to consider that the beta coeffs difffer from the regression coeffs by the ratio of sigmas of the variables--you don't need to rerun the regression to calculate that ratio from the estimation sample. The following routine, run after regress, will give back the vector of beta coeffs. If there is a constant in the original regression, its coefficient is returned as zero (since in version 7, matrices may not contain missing values).

*! betacoef 1.0.0 cfb 4112
program define betacoef, rclass
version 7.0

if "`e(cmd)'" != "regress" {
error 301
}
tempname b
/* get depvar and regressorlist from previous regression */
local depvar = e(depvar)
mat `b' = e(b)
local rvarlst : colnames `b'
local rvarlst : subinstr local rvarlst "_cons" "", /*
*/ word count(local hascons)

marksample touse
if "`sample'" == "" {
qui replace `touse' = 0 if !e(sample)
}

qui summ `depvar' if `touse'
scalar ysd = r(sd)
local i
foreach v of local rvarlst {
local i = `i'+1
qui summ `v' if `touse'
scalar sd`v' = r(sd)
mat `b'[1,`i'] = `b'[1,`i'] * sd`v' / ysd
}
* set to zero, not missing, for v7 compatibility
if (`hascons') {
mat `b'[1,`i'+1] = 0
}

return mat beta = `b'
end

*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index