Announcement

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

  • Cluster standard errors after xtivreg

    Dear Statalister,

    I am working on panel data for two years. I am estimating an RE2SLS estimator. The instrument is using is on the governorate level while the data is per individual on a more disaggregated level.
    So, I thought it is necessary to cluster the standard errors by governorate as in the code below:

    Code:
     xtset Findid year
    Code:
    xi: xtivreg $Y $X2 (endogvar= $IV) if female==0, re vce (cluster gov) first
    


    However, I get this error:
    panels are not nested within clusters
    r(498);


    How can I solve this problem and do the clustering?

    Thank you.
    Maye

  • #2
    Maye:
    I would find an instrument at individual level.
    Besides, I fail to get why you should cluster at governative level with data at individual level.
    Kind regards,
    Carlo
    (Stata 18.0 SE)

    Comment


    • #3
      Dear Carlo,
      I am clustering because my data is on the individual level and my instrument is on the governorate level. So, for individuals in the same governorate, the instrument is the same.
      There is no suitable instrument on the individual level, unfortunately.

      Best regards,
      Maye

      Comment


      • #4
        Maye:
        thanks for providing further clarifications.
        I do not know whether waht follows fits your case, but I would explore -egen- with -group- in searching for the chance to create a different panelid that takes governor level into account.
        Kind regards,
        Carlo
        (Stata 18.0 SE)

        Comment


        • #5
          Dear Carlo,
          Thanks for your suggestion.
          If I understand correctly, I create a new panelid that takes into account the individual and the governorate level. and this is the id that I announce in the -xtset- with the time variable.
          and then in the vce option I add only the governorate to cluster the standard errors by governorate.

          Comment


          • #6
            Maye:
            you're correct.
            Kind regards,
            Carlo
            (Stata 18.0 SE)

            Comment


            • #7
              I have a further question, clustering is still not allowed in -xtivreg-
              and I am doing an RE two stage least squares estimation due to limited within-subject variability for most of the variables. So, I can not use -xtivreg2-.
              The commands that I used include the bootstrapped standard errors that are clustered at the idgov level but not on the governorate level as follows:

              Code:
              egen idgov = group (Findid gov), label 
              xtset idgov year 
              xtivreg crhrsday $X10 (crtrvtmp= $IV) if female==1, re vce(bootstrap, reps(400) seed(1)) first small
              Is there any suggestions to be able to cluster on the governorate level?

              Best,
              Maye

              Comment


              • #8
                Maye:
                as per -help xtivreg- clustered standard errors seem to be allowed under -re- specification.
                Kind regards,
                Carlo
                (Stata 18.0 SE)

                Comment


                • #9
                  Following up on this, say your data is at individual level, instrument and independent variable at city level, data on 2 years, t and t+1. If you want to include city and year fixed effects, city-year fixed effects, and cluster SE on city year, what should be the code. xi: ivreg would not let me do a GMM or specify MLE stuff like ivreg 2sls does. If I use xtivreg it does not allow me to cluster SE with fe option I guess, nor does it love my i.year*i.city sort of syntax.

                  I want to run either some sort of this command:
                  egen cityear=group(city year)
                  xtivreg y i.year i.city i.city*i.year w u v (x=z ), fe cluster(cityear)


                  or

                  ivregress 2sls y i.year i.city i.city*i.year w u v (x=z ), fe cluster(cityear)

                  Can someone please tell me the appropriate code?

                  Comment

                  Working...
                  X