Announcement

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

  • Moran test and ivreg2

    Hi,

    I am running a Moran’s test of residual correlation with nearby residuals.
    I know that Moran runs on regress but if i run it after ivreg2 doesn't work
    this is a snipped of my code:


    foreach y of numlist 2013 2018 {
    sum vote_fdi`y'
    *** 2SLS
    ivreg2 vote_fdi`y' (opp_rate = iv_jmeansent), robust
    ivreg2 vote_fdi`y' (opp_rate = iv_jmeansent) $covars, robust
    }


    spmatrix create contiguity W, replace
    estat moran, errorlag(W)


    After running the test I get this error:
    estat moran not valid
    r(321);

    How can I solve this?
    Thanks everyone

  • #2
    The estat moran help file says that the test can be run after fitting a model using regress.
    Instead of ivregress you could do manual 2SLS,
    Code:
    regress opp_rate iv_jmeansent
    predict opp_rate_hat
    regress vote_fdi opp_rate_hat

    Comment


    • #3
      That worked!! thank you so much. I now have a similar problem but with a more tangled ivreg. here is my code:
      global covars = "c_ide c_antifascista pun_weak pun_strng"


      *IV
      est clear

      foreach y1 in vote_right1948{
      foreach y2 in vote_right1976{
      foreach y3 in vote_right2006{
      foreach x in opp_rate {
      foreach z in iv_jmeansent {
      ivreg2 `y1' (`x'=`z') $covars vote_fas1921, robust
      est store a1
      ivreg2 `y1' (`x'=`z') $covars vote_left1921, robust
      est store a2
      ivreg2 `y1' (`x'=`z') $covars pre_1922_opponents, robust
      est store a3
      ivreg2 `y2' (`x'=`z') $covars vote_fas1921, robust
      est store a4
      ivreg2 `y2' (`x'=`z') $covars vote_left1921, robust
      est store a5
      ivreg2 `y2' (`x'=`z') $covars pre_1922_opponents, robust
      est store a6
      ivreg2 `y3' (`x'=`z') $covars vote_fas1921, robust
      est store a7
      ivreg2 `y3' (`x'=`z') $covars vote_left1921, robust
      est store a8
      ivreg2 `y3' (`x'=`z') $covars pre_1922_opponents, robust
      est store a9

      esttab a1 a2 a3 a4 a5 a6 a7 a8 a9 using "ov.tex", replace label cells(b(fmt(3)) ///
      se(par fmt(3)) ) stats(N) ///
      keep(opp_rate vote_fas1921 vote_left1921 pre_1922_opponents)
      }
      }
      }
      }
      }


      I need to run the Moran test again and this is what I did for vote_right1948:
      regress opp_rate iv_jmeansent
      predict opp_rate_hat
      regress vote_right1948 opp_rate_hat $covars vote_fas1921

      But I get different results than the ivreg2. Am I missing something?

      Comment


      • #4
        include covariates in both stages,
        Code:
        regress opp_rate iv_jmeansent $covars vote_fas1921
        predict opp_rate_hat
        regress vote_right1948 opp_rate_hat $covars vote_fas1921

        Comment

        Working...
        X