Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Estimates post: matrix has missing values! for ivreg2

    Hi, guys!

    I received an error message "estimates post: matrix has missing values" when i'm using ivreg2. I've checked that there's no missing values in the y and controls. I really don't know how to handle this issue, any ideas are appreciated!!

    Here's my stata codes:

    local x1 male age agesq tmperiod
    local x2 s_age
    local x3 h_dfct

    xi: ivreg2 y (x = iv) `x1' i.educ i.employer2 i.industry i.marea `x2' i.s_educ `x3' i.p_prefect [pw = w_l], cluster(i.home_pref i.p_prefect) partial(i.p_prefect) first

    Best!
    Leo

  • #2
    One more thing, ivreg2 runs successfully if i remove the option part "cluster(i.home_pref i.p_prefect)". No error shows, but it's not the result i want. I need the clsuster for the final result.

    Comment


    • #3
      You don't want the i. in the cluster statement. While xi is not needed for recent Stata versions, I don't know about user-written ivreg2.

      Comment


      • #4
        You'll increase your chances of a useful answer by following the FAQ on asking questions - provide Stata code in code delimiters, readable Stata output, and sample data using dataex. And simplify what you post - you just make it harder for the reader by defining three locals that are just variable names.

        Comment


        • #5
          Originally posted by Phil Bromiley View Post
          You don't want the i. in the cluster statement. While xi is not needed for recent Stata versions, I don't know about user-written ivreg2.
          Dear Bromiley!

          Thanks for your suggestions and help. It really works out when i delete the term "i." in the cluster statement, however, another issue confused me as i add one more iv, here's my codes:

          xi: ivreg2 y3 (itnmarry = intmarry = iv_prefect0522 iv_05prob2) male age agesq i.educ i.employer2 i.industry i.marea i.home_provin i.p_prefect [pw = w_l], cluster(home_pref p_prefect) partial(i.home_provin i.p_prefect)

          My question is how to obtain Hansen J test statistic for over identification test.

          Click image for larger version

Name:	Picture1.png
Views:	1
Size:	163.8 KB
ID:	1506541

          Comment


          • #6
            I worked it out by two ways: mata and chi2 test:
            Here's my codes:
            *.(1) 2SLS, IVs: iv_prefect0522 iv_05prob2

            eststo clear

            foreach var of varlist y* {
            qui xi: ivreg2 `var' (intmarry = iv_prefect0522 iv_05prob2) `x1' i.educ i.employer2 i.industry i.marea `x2' i.s_educ `x3' i.home_provin i.p_prefect [pw = w_l], gmm2s cluster(home_pref p_prefect) partial(i.home_provin i.p_prefect)
            eststo `var'_iv1
            }
            outreg2 [*_iv1] using iv1, keep(intmarry) excel adds(Weak identification test, `e(widstat)') dec(3) ct(`var') replace

            *.(2) Calculate sargan statistic

            preserve
            gen cons = 1
            predict res, resid
            keep if e(sample)
            keep iv_prefect0522 iv_05prob2 male age agesq tmperiod _Ieduc_1-_Ieduc_3 _Imarea_2 _Imarea_3 s_age _Is_educ_1-_Is_educ_3 h_dfct _Ihome_prov_12-_Ihome_prov_65 _Ip_prefect_2-_Ip_prefect_308 cons res
            order iv_prefect0522 iv_05prob2 male age agesq tmperiod _Ieduc_1-_Ieduc_3 _Imarea_2 _Imarea_3 s_age _Is_educ_1-_Is_educ_3 h_dfct _Ihome_prov_12-_Ihome_prov_65 _Ip_prefect_2-_Ip_prefect_308 cons res

            clear mata
            mata:
            data = st_data(.,.)
            a = cols(data) - 1
            X = st_data(.,1..a)
            e = st_data(.,"res")
            V = e' * X * invsym(X' * X) * X' * e
            M = e' * e
            st_numscalar("V",V)
            st_numscalar("M",M)
            end

            scalar sargan = (e(N) * V) / M
            di %4.2f sargan
            di %4.3f chi2tail(1,sargan)
            restore

            *.(3) Follow the wooldrege

            use wjw17, clear

            local x1 male age agesq tmperiod
            local x2 s_age
            local x3 h_dfct

            eststo clear
            foreach var of varlist y* {
            qui {
            xi: ivreg2 `var' (intmarry = iv_prefect0522 iv_05prob3) `x1' i.educ i.marea `x2' i.s_educ `x3' i.home_provin i.p_prefect [pw = w_l], cluster(home_pref p_prefect) partial(i.home_provin i.p_prefect)
            eststo `var'_iv1
            preserve
            predict res,resid
            xi: reg res iv_prefect0522 iv_05prob2 `x1' i.educ i.marea `x2' i.s_educ `x3' i.home_provin i.p_prefect, r
            scalar sargan=e(N)*e(r2)
            }
            di %4.2f sargan
            di %4.3f chi2tail(1,sargan)
            restore
            }

            Comment

            Working...
            X