Announcement

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

  • First Stage F Statistics ivreg2



    Hello

    I am trying to use the following code to report the first stage results , I am unable to get the First Stage F-Statistics results in the output. what I am missing please.


    eststo:ivreg2 child_mortality ${child_vars} (PM2_5 = night_inversions), first savefirst savefprefix(first) saverf saverfprefix(reduced)
    cap estadd scalar cdf1 = `e(cdf)': s1pm
    cap estadd scalar sstat1 = `e(sstat)': s1pm
    esttab first* using motherworked,replace star(* 0.10 ** 0.05 *** 0.01) b(%8.2g) stats(cdf1 sstat1 r2 widstat N, labels( "CD Wald F" "SW S stat." "R-squared" "First Stage F-Statistics" "N"))



    data please

    clear
    input float(child_mortality male_child birth_order birth_weight birth_weight_record twin child_age pregnancy_duration PM2_5 night_inversions)
    0 0 10 909 0 1 20 25 27 1
    0 0 9 862 0 1 7 30 14 0
    0 0 5 684 0 0 11 29 88 1
    0 1 3 997 0 0 26 27 18 1
    0 0 9 828 0 0 34 27 39 1
    0 0 5 155 0 0 32 28 37 1
    0 0 2 602 1 0 10 25 60 0
    0 1 9 692 1 0 5 33 13 1
    0 1 2 387 0 1 21 28 61 0
    0 1 7 396 1 0 12 31 86 0
    0 1 8 303 0 1 10 27 12 0
    1 0 2 804 1 1 11 27 95 0
    1 1 9 116 1 0 31 30 44 1
    1 0 9 201 1 1 6 27 71 0
    0 1 5 325 1 0 3 26 68 0
    0 0 1 284 0 1 5 27 97 1
    0 0 3 435 0 0 17 32 31 1
    0 0 4 140 0 0 19 33 9 0
    0 1 10 697 1 1 33 27 2 0
    0 1 2 769 1 1 18 28 69 0
    0 0 6 496 1 1 11 28 66 1
    0 1 5 352 0 1 21 29 55 1
    1 1 6 120 1 1 16 27 23 1
    0 0 2 845 1 1 1 27 25 1
    0 1 9 327 0 0 7 34 75 1
    0 0 5 376 0 1 31 30 37 0
    0 0 6 29 0 1 17 33 35 1
    0 1 10 315 0 0 31 25 85 0
    0 1 7 264 1 0 31 28 41 0
    1 1 2 144 0 0 12 30 48 1
    0 1 8 556 0 1 15 29 99 0
    0 1 5 287 0 1 10 25 94 0
    0 1 5 924 0 1 30 27 75 1
    0 1 4 305 0 0 21 31 4 1
    0 0 8 129 1 0 1 26 36 1
    1 1 5 244 1 0 36 27 8 0
    0 1 5 662 0 1 6 32 28 0
    0 1 8 685 0 1 6 30 18 0
    0 0 10 210 0 0 18 25 83 1
    1 0 3 978 1 1 33 30 1 0
    0 0 6 546 1 1 10 32 5 1
    0 1 5 930 0 1 28 29 19 0
    0 0 8 995 1 0 15 32 7 1
    1 1 1 729 1 0 18 27 93 1
    0 0 9 379 0 1 12 29 56 1
    0 1 10 392 1 0 25 33 11 1
    0 1 7 351 1 0 25 31 70 1
    0 0 4 730 0 1 1 29 68 0
    1 1 2 653 1 0 33 26 41 1
    0 0 7 321 1 0 28 25 23 0
    0 0 4 510 0 0 12 29 1 1
    0 1 9 828 1 1 30 26 54 1
    0 1 6 439 1 1 9 29 74 1
    1 1 3 609 0 0 30 25 92 0
    0 1 1 221 0 0 33 28 51 0
    0 0 2 788 0 1 32 32 98 0
    0 1 7 505 1 0 1 27 90 1
    0 0 8 772 1 1 8 26 94 0
    1 0 3 419 0 0 28 25 48 0
    0 0 3 491 1 1 14 25 61 0
    0 1 5 821 0 1 33 28 78 0
    0 1 7 318 0 0 25 27 49 1
    0 1 4 564 1 1 20 28 41 0
    0 0 5 682 0 0 1 30 10 0
    0 0 4 771 1 0 6 25 37 1
    0 0 8 663 1 1 29 26 56 1
    1 0 5 587 0 0 20 29 62 1
    0 0 8 188 0 0 12 29 57 1
    0 1 9 196 1 0 20 33 61 1
    0 0 1 662 0 1 4 27 49 1
    0 0 9 666 0 0 19 29 40 0
    0 0 9 821 1 1 13 30 62 1
    0 0 7 329 1 0 11 33 92 1
    1 0 5 380 0 0 19 32 71 1
    1 1 3 596 0 0 36 31 7 0
    0 1 8 616 1 1 11 29 56 1
    0 0 1 788 1 0 33 26 55 1
    0 1 8 725 0 0 33 30 51 1
    0 1 8 512 0 0 19 30 75 0
    0 1 8 510 1 0 29 25 13 0
    0 0 6 374 1 1 9 27 89 1
    1 1 5 576 1 0 6 27 32 0
    0 1 6 677 0 0 30 25 6 1
    0 1 4 704 0 0 14 26 38 0
    0 1 10 886 1 0 20 26 36 0
    0 0 8 472 0 0 27 27 56 1
    0 0 4 706 0 0 35 26 100 1
    0 0 3 124 1 1 25 25 47 0
    1 0 3 837 0 0 30 25 56 1
    0 0 3 353 1 1 17 34 93 1
    0 0 9 711 0 1 15 33 77 1
    0 1 9 45 1 0 3 34 40 0
    0 1 2 406 1 1 7 27 33 1
    0 1 5 113 0 1 4 34 2 1
    0 1 9 441 1 0 26 27 19 1
    0 0 5 78 1 1 20 33 22 0
    1 0 9 58 0 1 11 28 20 1
    0 0 2 138 1 1 2 28 25 1
    0 1 2 240 0 0 22 26 56 0
    0 1 4 906 0 1 29 25 62 1
    end
    [/CODE]


  • #2
    Andrew Musau Please

    Comment


    • #3
      See #6: https://www.statalist.org/forums/for...-stage-outcome

      Comment


      • #4
        Thanks I have followed this post but its not working for me please
        This code I have generated by the help of the post in #3

        eststo:ivreg2 child_mortality ${child_vars} (PM2_5 = night_inversions), first savefirst savefprefix(first) saverf saverfprefix(reduced)
        cap estadd scalar cdf1 = `e(cdf)': s1pm
        cap estadd scalar sstat1 = `e(sstat)': s1pm
        esttab first* using motherworked,replace star(* 0.10 ** 0.05 *** 0.01) b(%8.2g) stats(cdf1 sstat1 r2 widstat N, labels( "CD Wald F" "SW S stat." "R-squared" "First Stage F-Statistics" "N"))

        Comment


        • #5
          Andrew Musau Please

          Comment


          • #6
            Code:
            eststo m1: ivreg2 child_mortality ${child_vars} (PM2_5 = night_inversions), first savefirst savefprefix(first) saverf saverfprefix(s1)
            cap estadd scalar cdf1 = `e(cdf)': s1PM2_5
            cap estadd scalar sstat1 = `e(sstat)': s1PM2_5
            qui reg `e(instd)' `e(insts)' if e(sample)
            estadd scalar F1 =  `=e(F)': s1PM2_5
            esttab s1PM2_5 m1 using motherworked, replace star(* 0.10 ** 0.05 *** 0.01) b(%8.2g) stats(cdf1 sstat1 r2 F1 N, labels( "CD Wald F" "SW S stat." "R-squared" "First Stage F-Statistics" "N"))
            Last edited by Andrew Musau; 11 Apr 2023, 09:20.

            Comment


            • #7
              @Andrew Musau
              Thanks

              Comment


              • #8
                I got an error for the following program. The error is "invalid syntax r(198);" which seems to be in the last step. I highly appreciate anyone who can help solve this problem. I think Andrew Musau has expertise. Thank you! * Load example dataset
                sysuse auto, clear

                * Run IV regression and save first-stage results
                ivreg2 price i.rep78 (foreign = weight turn trunk), first savefirst savefprefix(fs)

                * Save second-stage regression
                est store second

                * Restore and store first-stage regression
                est restore fsforeign
                est store first

                * Export first-stage regression
                outreg2 [first] using "myfile.rtf", replace dec(2) ///
                title("First Stage Regression")

                * --- Extract statistics for addstat() ---
                scalar cdf1 = e(cdf) // Cragg-Donald F-stat
                scalar sstat1 = e(sstat) // Stock-Yogo S statistic
                scalar r2 = e(r2) // R-squared
                scalar N = e(N) // Sample size

                * Manually compute first-stage F-statistic
                qui reg foreign weight turn trunk i.rep78 if e(sample)
                scalar F1 = e(F)

                * Append second-stage regression with full diagnostics
                outreg2 [second] using "myfile.rtf", append dec(2) ///
                addstat("CD Wald F", cdf1, "SW S stat.", sstat1, ///
                "R-squared", r2, "First Stage F-Stat", F1, "N", N) ///
                title("Second Stage Regression")

                Comment


                • #9
                  The statistics "cdf1" through "N" are only available after the second stage regression. Otherwise, your scalars are empty (see highlighted to restore these estimates). Note that the R2 statistic is outputted automatically, but it is meaningless in 2SLS regressions.

                  Code:
                  sysuse auto, clear
                  
                  * Run IV regression and save first-stage results
                  ivreg2 price i.rep78 (foreign = weight turn trunk), first savefirst savefprefix(fs)
                  
                  * Save second-stage regression
                  est store second
                  
                  * Restore and store first-stage regression
                  est restore fsforeign
                  est store first
                  
                  * Export first-stage regression
                  outreg2 [first] using "myfile.rtf", replace dec(2) ///
                  title("First Stage Regression")
                  
                  est restore second
                  * --- Extract statistics for addstat() ---
                  scalar cdf1 = e(cdf) // Cragg-Donald F-stat
                  scalar sstat1 = e(sstat) // Stock-Yogo S statistic
                  scalar r2 = e(r2) // R-squared
                  scalar N = e(N) // Sample size
                  
                  * Manually compute first-stage F-statistic
                  qui reg foreign weight turn trunk i.rep78 if e(sample)
                  scalar F1 = e(F)
                  
                  * Append second-stage regression with full diagnostics
                  outreg2 [second] using "myfile.rtf", append dec(2) ///
                  addstat("CD Wald F", cdf1, "SW S stat.", sstat1, ///
                  "R-squared", r2, "First Stage F-Stat", F1, "N", N) ///
                  title("Second Stage Regression")



                  Comment


                  • #10
                    Thank you, Andrew Musau! I have another question. If I used the following program, how can I append second-stage regression with full diagnostics? Thank you agin.


                    sysuse auto, clear
                    ivreg2 price i.rep78 (foreign = weight turn trunk), first savefirst
                    est restore _ivreg2_foreign
                    outreg2 using "myfilex.rtf", replace
                    ivreg2 price i.rep78 (foreign = weight turn trunk)
                    outreg2 using "myfilex.rtf", append

                    Comment


                    • #11
                      Originally posted by Pradeep Fonseka View Post
                      how can I append second-stage regression with full diagnostics?
                      What do you mean by full diagnostics?

                      Comment

                      Working...
                      X