Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: re: Program for OLS regression coefficients using weights


From   Kit Baum <baum@bc.edu>
To   statalist@hsphsun2.harvard.edu
Subject   st: re: Program for OLS regression coefficients using weights
Date   Thu, 18 Jun 2009 11:32:15 -0400

<>
Sylke said

I would need to write a programme that gives me the b coefficients of an OLS regression, using weights. This is an easy task if no weights are used with b being (X'X)-1(X'Y): mat accum xprimex = x mat vecaccum yprimex = y x *Transpose mat xprimey =yprimex' mat b = inv(xprimex)*(xprimey) mat list b However, I would like to estimate b=(X'DX)-1 X'DY, hence applying design weights. D is now a diagonal weight matrix. Martin suggested Mata. No need for Mata here, though, if you're just trying to apply a diagonal matrix of weights stored in a variable:

sysuse auto,clear
replace foreign = 2*foreign
replace foreign = 10 if foreign==0
reg price weight turn [iw=foreign^2]
g wprice = foreign*price
g wweight = foreign*weight
g wturn = foreign*turn
reg wprice wweight wturn foreign, nocons

Kit

Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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