Statalist


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

st: AW: re: Program for OLS regression coefficients using weights


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: re: Program for OLS regression coefficients using weights
Date   Thu, 18 Jun 2009 17:44:08 +0200

<> 

The Mata suggestion grew more out of Sylke`s concern over -matsize- which I
thought could be circumvented via Mata... 



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Kit Baum
Gesendet: Donnerstag, 18. Juni 2009 17:32
An: [email protected]
Betreff: st: re: Program for OLS regression coefficients using weights

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


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index