Announcement

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

  • export the output of first-stage in the excel

    Hello dear all,
    I work in panel data and try to export the first and second stage in excel. but I can only export the second stage.

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float lGDP_PC_REAL_PPP double(shock instrument) long REG_ID2 double year
            .                      0                0 1 1990
            .                      0                0 1 1991
            .                      0                0 1 1992
            .                      0                0 1 1993
            .                      0                0 1 1994
            .                      0                0 1 1995
            .                      0                0 1 1996
            .                      0                0 1 1997
            .                      0                0 1 1998
            .                      0                0 1 1999
    10.260042                      0                0 1 2000
    10.273222                      0                0 1 2001
    10.307752                      0                0 1 2002
     10.32065                      0 8.44299030303955 1 2003
    10.355614                      0                0 1 2004
    10.341162                      0                0 1 2005
    10.350286                      0                0 1 2006
     10.38727                      0                0 1 2007
     10.38307                      0                0 1 2008
     10.36445    .047485727816820145 8.44299030303955 1 2009
      10.3917                      0                0 1 2010
    10.415712                      0                0 1 2011
     10.44074 .000051514729420887306 8.44299030303955 1 2012
    10.445143                      0                0 1 2013
    10.446596                      0 8.44299030303955 1 2014
    10.456137                      0                0 1 2015
     10.47161                      0 8.44299030303955 1 2016
    10.506327                      0                0 1 2017
    10.513226                      0                0 1 2018
            .                      0                0 1 2019
            .                      0                0 2 1990
            .                      0                0 2 1991
            .                      0                0 2 1992
            .                      0                0 2 1993
            .                      0                0 2 1994
            .                      0                0 2 1995
            .                      0                0 2 1996
            .                      0                0 2 1997
            .                      0                0 2 1998
            .                      0                0 2 1999
    10.487573                      0                0 2 2000
     10.48243                      0                0 2 2001
     10.48841                      0                0 2 2002
     10.49662                      0 8.44299030303955 2 2003
    10.533055                      0                0 2 2004
    10.533322                      0                0 2 2005
    10.564732                      0                0 2 2006
    10.610587                      0                0 2 2007
    10.625587                      0                0 2 2008
    10.578547    .047485727816820145 8.44299030303955 2 2009
    10.591572                      0                0 2 2010
     10.61771                      0                0 2 2011
    10.620815 .000051514729420887306 8.44299030303955 2 2012
    10.614622                      0                0 2 2013
    10.618322                      0 8.44299030303955 2 2014
     10.62162                      0                0 2 2015
    10.629295                      0 8.44299030303955 2 2016
    10.656435                      0                0 2 2017
     10.68389                      0                0 2 2018
            .                      0                0 2 2019
            .                      0                0 3 1990
            .                      0                0 3 1991
            .                      0                0 3 1992
            .                      0                0 3 1993
            .                      0                0 3 1994
            .                      0                0 3 1995
            .                      0                0 3 1996
            .                      0                0 3 1997
            .                      0                0 3 1998
            .                      0                0 3 1999
    11.020496                      0                0 3 2000
     11.03114                      0                0 3 2001
    11.042217                      0                0 3 2002
    11.028125                      0 8.44299030303955 3 2003
    11.027865                      0                0 3 2004
     11.03292                      0                0 3 2005
    11.058323                      0                0 3 2006
    11.071346                      0                0 3 2007
    11.082542                      0                0 3 2008
    11.053268    .047485727816820145 8.44299030303955 3 2009
     11.06139                      0                0 3 2010
    11.068215                      0                0 3 2011
     11.05189 .000051514729420887306 8.44299030303955 3 2012
    11.035276                      0                0 3 2013
     11.01735                      0 8.44299030303955 3 2014
    11.003665                      0                0 3 2015
    11.015855                      0 8.44299030303955 3 2016
     11.00649                      0                0 3 2017
    11.018416                      0                0 3 2018
            .                      0                0 3 2019
            .                      0                0 4 1990
            .                      0                0 4 1991
            .                      0                0 4 1992
            .                      0                0 4 1993
            .                      0                0 4 1994
            .                      0                0 4 1995
            .                      0                0 4 1996
            .                      0                0 4 1997
            .                      0                0 4 1998
            .                      0                0 4 1999
    end
    label values REG_ID2 REG_ID2
    label def REG_ID2 1 "AT11", modify
    label def REG_ID2 2 "AT12", modify
    label def REG_ID2 3 "AT13", modify
    label def REG_ID2 4 "AT21", modify
    ------------------ copy up to and including the previous line ------------------

    Listed 100 out of 15167 observations
    Use the count() option to list more

    .

    and

    Code:
    forvalues i = 0/4{ 
    
    ivreghdfe f`i'.lGDP_PC_REAL_PPP (shock=instrument) l(1/2)shock l(1/2)lGDP_PC_REAL_PPP, absorb(i.REG_ID2 i.year) cluster(REG_ID2) first 
    
    outreg2 using iv_lGDP_PC_REAL_PPP.xls, append label keep( shock l(1/2).shock l(1/2).lGDP_PC_REAL_PPP)   bdec(3) cdec(3) stats(coef se) addstat(Kleibergen-Paap_rk_LM_statistic, `e(idstat)', p-value, `e(idp)', Kleibergen-Paap_rk_Wald_F_statistic, `e(widstat)')  
    }



    I appreciate receiving your help.

    Best,
    Last edited by Khati Zolfaghari; 13 Aug 2023, 10:34.

  • #2
    asdoc ivreghdfe, works

    Or this for a more traditional outreg2 view.

    Code:
     
     sysuse auto, clear  capture program drop res2doc program res2doc eststo second  //store the second-stage results eststo first: reghdfe `e(instd)' `e(exexog)' `e(inexog)' , absorb(`e(absvars)') cluster(`e(absvars)') //run and store the first-stage outreg2 [first second] using myresults, word replace see  end  ivreghdfe price weight headroom (mpg = foreign) , absorb(rep78) cluster(rep78) first res2doc

    Comment


    • #3
      @ George Ford thanks for your reply.

      I try also to follow https://www.statalist.org/forums/for...om-first-stage
      and try to add the F-test to the table also:

      Code:
      clear all
      
      
      forvalues i = 0/4{ 
      
      ivreghdfe f`i'.lGDP_PC_REAL_PPP (shock=instrument) l(1/2)shock l(1/2)lGDP_PC_REAL_PPP, absorb(i.REG_ID2 i.year) cluster(REG_ID2) first
      g sample_`i' = e(sample)
      local excluded= e(exexog)
      reghdfe `e(instd)' `e(insts)' if sample_`i', absorb(`e(absvars)')
      test `excluded'
      
      outreg2  using iv.xls, append   stats(coef se)
      
      
      }

      best regards,

      Comment


      • #4
        Code:
        sysuse auto, clear
        
        capture program drop res2doc
        program res2doc
        eststo second  //store the second-stage results
        local add: di %5.3f `e(widstat)'
        di `add'
        eststo first: reghdfe `e(instd)' `e(exexog)' `e(inexog)' , absorb(`e(absvars)') cluster(`e(absvars)') //run and store the first-stage
        outreg2 [first second] using myresults, addtext(Ftest IV = `add') word replace see 
        end
        
        ivreghdfe price weight headroom (mpg = foreign) , absorb(rep78) cluster(rep78) first
        res2doc

        Comment


        • #5
          @George Ford thanks for your reply.


          Best regards.

          Comment


          • #6
            Hello George,

            How can we add the p-value to the Kleibergen-Paap Wald rk F statistic you have added to the table? I'm not able to locate its p-value in the stored results.

            Thank you.

            Comment


            • #7
              Code:
              sysuse auto, clear
              
              capture program drop res2doc
              program res2doc
              eststo second  //store the second-stage results
              local add: di %5.3f `e(widstat)'
              local add2: di %5.3f `e(idp)'
              eststo first: reghdfe `e(instd)' `e(exexog)' `e(inexog)' , absorb(`e(absvars)') cluster(`e(absvars)') //run and store the first-stage
              outreg2 [first second] using myresults, addtext(Ftest IV = `add' [prob = `add2'] ) word replace  
              end
              
              ivreghdfe price weight headroom (mpg = foreign) , absorb(rep78) cluster(rep78) first
              res2doc

              Comment


              • #8
                Thank you, George.

                Comment

                Working...
                X