<>
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/