Announcement

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

  • Help with command of cluster standard error in ivregress2 and export both stages results

    Hello everyone. I am using instrumental variable analysis and I use ivregress2 2sls to export the results of both first and second stages. It works quite well and commands are somehow similar to ivregress 2sls (or ivreg2). However, when I want to control for cluster standard error and export result, I can't run the command with ivregress2 2sls, although it still works perfectly with ivregress 2sls and ivreg2.
    My correct commands are:

    . ivreg2 frate_2000 (frate_1991= field_dummy), cluster(Region) first
    . ivregress 2sls frate_2000 (frate_1991= field_dummy), cluster(Region) first

    But these don't work for ivregress2
    . ivregress2 2sls frate_2000 (frate_1991= field_dummy), cluster(Region) first
    or ivregress2 2sls frate_2000 (frate_1991= field_dummy), vce(cluster Region) first

    Does anyone know the command of cluster standard error for ivregress2 please help me? Or instead if someone know how to export the results of instrumental variable regression both first and second stages with ivgress 2sls or ivreg2 please help me.
    (I only can export result of first stage with ivregress2 by outreg2, I did search and read a lot on the internet but I still can't do with ivreg2 and ivregress by estout package )

    Thank you very much!
    Last edited by Jena Do; 12 Aug 2016, 07:42.

  • #2
    Can you include the error messages you get? And perhaps also a small sample of your data using -dataex-

    Comment


    • #3
      Dear Jesse, this is the errors I got:

      . ivregress2 2sls frate_2000 (frate_1991= field_dummy),Cluster(Region) first //with capital 'c' in 'Cluster'
      option Cluster() not allowed
      r(198);

      . ivregress2 2sls frate_2000 (frate_1991= field_dummy),cluster(Region) first //with normal 'c' in 'cluster'
      no observations
      r(2000);


      . ivregress2 2sls frate_2000 (frate_1991= field_dummy), vce(cluster Region) first
      no observations
      r(2000);

      here is a piece of my data for example:

      . dataex frate_2000 frate_1991 field_dummy Region

      ----------------------- copy starting from the next line -----------------------
      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(frate_2000 frate_1991) double field_dummy str24 Region
            
      10.448872  5.045312 0 "North East"              
      11.622473   4.76869 0 "North East"              
      11.364738  4.969789 1 "North East"              
      15.286788  5.519967 1 "North East"                   
      13.480223  6.775929 1 "North West"              
      16.529087  6.774454 0 "North West"              
      10.773923   10.5647 0 "Yorkshire and the Humber"
        11.5691  10.00774 0 "Yorkshire and the Humber"
      12.753193  7.577414 0 "Yorkshire and the Humber"
       10.58984  6.977619 1 "East Midlands"           
      10.469102  7.224695 0 "East Midlands"           
      18.845837 11.494378 0 "East Midlands"                   
      19.361956 10.634977 1 "West Midlands"           
      10.798983  5.902836 1 "West Midlands"           
      17.244043  12.34627 1 "South West Region"       
      13.244992  7.468627 0 "South West Region"       
      16.066195 12.354917 0 "South West Region"          
      11.568303  7.621203 0 "East"                    
      14.017346  7.495773 0 "East"                    
       14.55356  7.497858 0 "East"                                  
       13.52506  8.796475 0 "South East"              
       13.36839  7.566463 0 "South East"              
      15.806643  7.556275 0 "South East"              
                                      
      end
      Thanks for your reply.

      Comment


      • #4
        It seems to be an issue with the ivregress2 command (which is quite old). The "no observations" seems to result from clustering on a string variable. But encoding it using -encode- lead to a new error message

        Code:
                   _iv_vce_wrk():  3001  expected 21 arguments but received 20
                         <istmt>:     -  function returned error
        Which means absolutely nothing to me. As you're using 2SLS, perhaps you can simply do the first stage regression manually, get that output and then do the 2sls regression with the more robust ivreg2 command and get that output for the second stage?

        Comment


        • #5
          Thank you, Jesse.
          But I don't understand what you said about 'simply do the first stage regression manually'. How can I do it? Or you mean I may type manually the result of first stage?
          By the way, do you know how to export the result of first stage with ivreg2? If yes could you please show me in as detailed as possible so that I no longer need ivregress2 anymore

          Comment


          • #6
            Originally posted by Jena Do View Post
            Thank you, Jesse.
            But I don't understand what you said about 'simply do the first stage regression manually'. How can I do it? Or you mean I may type manually the result of first stage?
            By the way, do you know how to export the result of first stage with ivreg2? If yes could you please show me in as detailed as possible so that I no longer need ivregress2 anymore
            Imagine you have a structural (second stage) equation: y = b1*x + u (_it subscripts suppressed, u is an error term)
            You want to instrument x with z
            Then in 2sls, you have a auxiliary (first stage) equation: x = c1*z + e (same as above, with e as error term)
            This gives you the fitted values x_hat (c1_hat*z), which will be correlated to y, but not to u.
            Then, the structural equation is (sort of) estimated using these x_hat. I say sort of, because this would lead to incorrect standard errors, but conceptually that's the idea.

            As a result, if you want the results from the 1st stage regression, you could run the x = c1*z + e regression yourself. You can check to see if the results are the same as the first stage results expressed by ivreg2. The 2nd stage results can then be obtained by running ivreg2 as you normally would.

            Comment


            • #7
              I tried both. The results are somehow similar but not completely the same. Anyway, thank you very much for your suggestion

              Comment


              • #8
                Although it is an old thread, just an additional element to the problem. Clustering with ivregress2 seems to work perfectly in STATA 14.0 (rev. May 5, 2015), but the error message in post #4 pops up in STATA 14.2 (rev. January 29, 2018) using the same code.

                The code which was tested in both versions
                Code:
                webuse auto
                ivregress2 2sls mpg weight (length=displacement), first
                ivregress2 2sls mpg weight (length=displacement), vce(cluster foreign)
                The error message from STATA 14.2 is:
                Code:
                . ivregress2 2sls mpg weight (length=displacement), vce(cluster foreign)
                           _iv_vce_wrk():  3001  expected 21 arguments but received 20
                                 <istmt>:     -  function returned error

                Comment


                • #9
                  Hello, I have this same problem when trying to cluster my regressions using ivregress2 2sls. Is there any solution?

                  Comment


                  • #10
                    This problem is present in Stata 17 as well.

                    Comment

                    Working...
                    X