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

st: re: Program for OLS regression coefficients using weights

From   Kit Baum <>
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 Baum   |   Boston College Economics & DIW Berlin   |
An Introduction to Stata Programming |
   An Introduction to Modern Econometrics Using Stata  |

*   For searches and help try:

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