Statalist


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

st: RE: replace VC matrix in ivreg


From   "Rodrigo Alfaro A." <[email protected]>
To   <[email protected]>
Subject   st: RE: replace VC matrix in ivreg
Date   Thu, 30 Oct 2008 10:25:36 -0300

///

Sasha,

That is simple, I wrote a non-efficient version where P is computed. But
the code will give some ideas about your question. 

Best regards, Rodrigo.


******************
program define myiv2, eclass
    version 9.2
    syntax varlist [if] [in], Instruments(varlist) 
    qui {
        marksample touse
        tempvar ones
        tempname b V
        gen `ones' =1
        local endos "`varlist' `ones'"
        tokenize `varlist' 
        local lhs `1'
        mac shift
        local rhs `*'
        local endo : word count `rhs'
        local exogs "`instruments' `ones'"
        sum `lhs' if `touse', meanonly
        local nobs = r(N) 
        local dof = `nobs'  - (`endo' + 1)
        
        mata: ivest("`endos'","`exogs'","`touse'")

        mat `b' = __b
        mat `V' = __V
        mat colnames `b' =  `rhs' _cons
        mat colnames `V' =  `rhs' _cons
        mat rownames `V' =  `rhs' _cons
        eret post `b' `V', dof(`dof') obs(`nobs') depname(`lhs')
        noi eret di
    }
end


mata: 
void ivest(string scalar vn1, string scalar vn2, string scalar touse) 
{
    real matrix W, y, X, Z, P, b, V, D, L, M, Vr
    real colvector e
    real scalar n, k
    string rowvector vars1, vars2
    string scalar v1, v2
    vars1 = tokens(vn1)
    vars2 = tokens(vn2)
    v1 = vars1[|1,.|]
    v2 = vars2[|1,.|]
    st_view(W,.,v1,touse)
    st_view(Z,.,v2,touse)
    st_subview(y,W,.,1)
    st_subview(X,W,.,(2\.))
    P=Z*invsym(Z'Z)*Z'
    n=rows(P)
    D=invsym(X'*P*X)
    b=D*(X'*P*y)
    e=(y - X*b) 
    V = D*(e'e/(rows(X)-cols(X)))
    M = diag(e*e')        
    V= D*X'*P*M*P*X*D'*(n/(rows(X)-cols(X)))
    st_matrix("__b",b')
    st_matrix("__V",V)
} 

end

-----Mensaje original-----
De: [email protected]
[mailto:[email protected]] En nombre de Sasha
Shepotylo
Enviado el: Jueves, 30 de Octubre de 2008 08:59 a.m.
Para: [email protected]
Asunto: st: replace VC matrix in ivreg

Dear Statalist users,

I programed calculation of HAC robust VC matrix in Mata and stored it as
Stata matrix called A using the following Mata command:

st_matrix("A", A).

I would like to keep coefficients computed by ivreg command, replace the
variance-covariance matrix computed by ivreg command with my matrix A,
and output the result in a standard table with coefficients, standard
errors, etc.

Can you suggest how can I do that?

Best,

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

********************************************************************************
ADVERTENCIA: La  información  contenida  en  esta  transmisión, y  en  cualquier archivo  adjunto, está  sujeta a reserva legal conforme a la normativa aplicable  al  Banco  Central  de  Chile, y  no  puede  ser usada o difundida  por personas distintas  de  su o sus destinatarios. Si usted ha recibido esta transmisión por error,  por  favor  notifique  inmediatamente al remitente respondiendo por este mismo medio y elimínela de su sistema.
El  Banco Central de Chile no se hará responsable de la exactitud y veracidad de la información contenida en este mensaje, así  como  de su  modificación, copia, divulgación  o  reenvío,  total  o  parcial.   Su  uso  no  autorizado puede ser sancionado de conformidad con las leyes chilenas. 
El  Banco  Central  de  Chile  transmite  sus decisiones a través de comunicados oficiales, los  que  pone  a  disposición  del público en su página de Internet: www.bcentral.cl 


DISCLAIMER: The information  contained  in  this  email or any attached file, is subject to legal  privilege  pursuant  to the laws and regulations applicable to the Central  Bank  of  Chile , and may not be used or disseminated by any person other  than  its  intended recipients. If you have received this transmission in error, please  notify  the sender immediately by reply to this email address and delete it from your system.
The Central Bank  of  Chile shall not be liable for the accuracy or authenticity of the contents of this message, whether amended, copied, forwarded or disclosed in  any  form, in  whole  or  in part.  Please note that unauthorized use may be penalized  in  conformity  with  the  Chilean law.    
The Central  Bank of Chile communicates its decisions by  official releases, and 
makes them available to the public in its WebPages: www.bcentral.cl

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