Announcement

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

  • Help needed: Export F-stats and P-values to an excel file

    Hi,

    I am using Stata 17 and need help in exporting results from Stata to excel. Here is an example of my data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(korea uk germany Four_WD) double engine_sizeL byte(turbo_premium full_manual full_airbags tire_pressure_monitor parking_aid transmission_warranty) int(person_1 person_2)
    0 0 1 1   2 0 0 0 1 1  4  40  45
    0 0 0 0 5.3 0 0 0 1 1  5  25  30
    0 0 0 1   2 0 0 0 1 1  4  30 100
    0 0 0 1   2 0 0 0 1 0  6  50 110
    0 0 0 0 2.4 0 0 1 1 0  5 100  60
    0 0 0 1 5.6 0 0 0 1 1  5  26  45
    1 0 0 0   2 0 0 0 1 0 10  25  40
    0 0 0 0 3.6 0 0 0 1 1  6  30  40
    0 0 0 0 2.5 0 0 0 1 0  5  30  50
    0 0 0 0 6.2 0 0 1 1 1  6  20  50
    0 1 0 1   2 0 0 0 1 0  5 120  90
    0 0 1 1   2 0 0 0 1 0  4  80  85
    0 0 1 1   3 0 0 0 1 1  4 100  55
    0 1 0 1   2 0 0 0 1 1  4 120  70
    0 0 0 1 6.2 0 0 0 1 1  6  30  55
    0 0 0 0 3.6 0 0 0 1 0  5  45  95
    1 0 0 1   2 0 0 0 1 0 10  30  45
    0 0 0 1 5.3 0 0 0 1 1  5  20  40
    0 0 0 0 2.5 0 1 0 1 0  5  30  45
    0 0 0 0 6.2 0 1 0 0 0  5  40  55
    0 0 0 0 1.5 0 0 0 1 0 10  30  50
    0 0 1 1   2 0 0 0 1 0  4  75  60
    0 0 0 0 2.4 0 0 0 1 0  5  20  50
    0 0 0 0 3.5 0 0 0 1 0  5  25  45
    0 0 1 0   2 0 0 0 1 0  4  60  70
    0 0 0 0   2 0 0 0 1 1  5  40  60
    0 0 0 1 2.4 0 0 0 1 0  5  80  50
    0 0 0 0 3.5 0 0 0 1 1  5  70  50
    0 0 0 0 5.7 0 1 0 1 0  5  90  60
    0 1 0 1   3 0 0 0 1 1  5 120  90
    0 0 0 1 1.5 0 0 0 1 0  5  25  50
    0 0 0 0 3.5 1 0 0 1 0  5  45  55
    0 0 0 0 6.2 0 1 0 0 1  5  40  50
    1 0 0 1   5 0 0 1 1 1 10  50  60
    0 0 0 1   2 0 0 0 1 0  6  40  60
    0 0 0 0 3.5 0 0 0 1 1  6  65  75
    0 0 1 0   3 0 0 0 1 0  3  90  90
    0 0 0 0 2.4 0 0 0 1 0  4  80  40
    0 0 0 1   2 0 0 0 1 0  5 100  45
    0 0 0 0 3.6 0 0 0 1 0  5  90  55
    end
    This is not the full variables list as I have to limit the number of variables to use dataex but this is my code for joint hypothesis:

    Code:
    foreach y of varlist person_* {
        reg `y' korea1 korea2 uk1 uk2 germany1 germany2 Four_WD1 Four_WD2 engine_sizeL1 engine_sizeL2 turbo_premium1 turbo_premium2 full_manual1 full_manual2 full_airbags1 full_airbags2 tire_pressure_monitor1 tire_pressure_monitor2 parking_aid1 parking_aid2 transmission_warranty1 transmission_warranty2 g1 g2, robust
        test _b[korea1] = _b[korea2], notest
        test _b[uk1] = _b[uk2],accum notest
        test _b[germany1] = _b[germany2],accum notest
        test _b[Four_WD1] = _b[Four_WD2],accum notest
        test _b[engine_sizeL1] = _b[engine_sizeL2],accum notest
        test _b[turbo_premium1] = _b[turbo_premium2],accum notest
        test _b[full_manual1] = _b[full_manual2],accum notest
        test _b[full_airbags1] = _b[full_airbags2],accum notest
        test _b[tire_pressure_monitor1] = _b[tire_pressure_monitor2],accum notest
        test _b[parking_aid1] = _b[parking_aid2],accum notest
        test _b[transmission_warranty1] = _b[transmission_warranty2] ,accum notest
        test _b[g1] = _b[g2] ,accum
        
    }
    Here is a sample of the F-stat and p-values results:

    Code:
    F( 12,    56) =    1.64
    Prob > F =    0.1080

    I want to export the F-stats and p-values to an excel file.

    Any help in this area would be appreciated. Thanks.



  • #2
    The sample data set does not contain all the variables used in the regression statement so I was not able to test it. Here is an example using simulated data, hope they will be somewhat useful:
    Code:
    clear
    set obs 100
    forvalues i = 1/10{
        gen y`i' = runiform()
    }
    forvalues i = 1/3{
        gen x`i' = runiform()
    }
    
    putexcel set theoutput.xlsx, sheet(page1) modify
    scalar k = 1
    foreach i of varlist y*{
    reg `i' x1 x2 x3
    test _b[x1] = _b[x2], notest
    test _b[x1] = _b[x3], accum notest
    test _b[x2] = _b[x3], accum
    putexcel A`=k' = `r(F)'
    putexcel B`=k' = `r(p)'
    scalar k = k + 1
    }

    Comment

    Working...
    X