如何保存stata的结果

来源:百度文库 编辑:神马文学网 时间:2024/04/29 21:24:48
Can I make regression tables that look like those in journal articles?This FAQ illustrates the outreg command that makes regression tables in a format that is commonly used in journal articles. The outreg command was written by John Luke Gallup and appears in the Stata Technical Bulletin #49. You can download outreg from within Stata by typing findit outreg (see How can I use the findit command to search for programs and get additional help? for more information about using findit).

Let's illustrate use of the outreg command using the high school and beyond data file we use in our Stata Classes.
use http://www.ats.ucla.edu/stat/stata/notes/hsb1, clear(highschool and beyond (200 cases))
We will run 3 regression models predicting the variable read.  The first model will predict from the variable write, the second model will predict from math and write, and the third model will predict from socst, math, and write. We will use outreg to create a single table that will summarize these models side by side.
regress read writeSource |       SS       df       MS                  Number of obs =     200---------+------------------------------               F(  1,   198) =  109.52Model |  7450.28755     1  7450.28755               Prob > F      =  0.0000Residual |  13469.1324   198  68.0259215               R-squared     =  0.3561---------+------------------------------               Adj R-squared =  0.3529Total |    20919.42   199  105.122714               Root MSE      =  8.2478------------------------------------------------------------------------------read |      Coef.   Std. Err.       t     P>|t|       [95% Conf. Interval]---------+--------------------------------------------------------------------write |     .64553   .0616832     10.465   0.000       .5238896    .7671704_cons |   18.16215   3.307162      5.492   0.000       11.64037    24.68394------------------------------------------------------------------------------
Here we use outreg to capture the results from the prior model, storing the output in the file test.doc and we suppress the variable labels and indicate we want to replace test.doc if it already existed.
outreg using test.doc, nolabel replace
Now we run our second regression model.
regress read math writeSource |       SS       df       MS                  Number of obs =     200---------+------------------------------               F(  2,   197) =   96.80Model |    10368.63     2  5184.31501               Prob > F      =  0.0000Residual |    10550.79   197  53.5573096               R-squared     =  0.4956---------+------------------------------               Adj R-squared =  0.4905Total |    20919.42   199  105.122714               Root MSE      =  7.3183------------------------------------------------------------------------------read |      Coef.   Std. Err.       t     P>|t|       [95% Conf. Interval]---------+--------------------------------------------------------------------math |   .5196538   .0703972      7.382   0.000        .380825    .6584826write |   .3283984   .0695792      4.720   0.000       .1911828    .4656141_cons |   7.541599    3.26819      2.308   0.022       1.096471    13.98673------------------------------------------------------------------------------
We run outreg again to capture the results of the second model, appending these results to the previous ones in test.doc.
outreg using test.doc, nolabel append
Now we run our third regression model.
regress read science socst math write Source |       SS       df       MS                  Number of obs =     195---------+------------------------------               F(  4,   190) =   65.23Model |  11608.8938     4  2902.22346               Prob > F      =  0.0000Residual |  8453.08565   190  44.4899245               R-squared     =  0.5787---------+------------------------------               Adj R-squared =  0.5698Total |  20061.9795   194  103.412265               Root MSE      =  6.6701------------------------------------------------------------------------------read |      Coef.   Std. Err.       t     P>|t|       [95% Conf. Interval]---------+--------------------------------------------------------------------science |   .2657521   .0648044      4.101   0.000       .1379236    .3935806socst |   .2808959   .0581116      4.834   0.000       .1662691    .3955227math |   .2961578   .0743467      3.983   0.000       .1495068    .4428087write |   .1141745   .0724559      1.576   0.117      -.0287468    .2570959_cons |   2.001966   3.163988      0.633   0.528      -4.239088    8.243021------------------------------------------------------------------------------
We run outreg again to capture the results of the third model.
outreg using test.doc, nolabel append
The contents of test.doc look like those below. Tabs are used between columns to get the columns to line up, so you will need to adjust your tab settings to get the tables to look as you desire.We have manually adjusted the spacing to show the columns properly.
                (1)      (2)      (3)read     read     readwrite           0.646    0.328    0.114(10.47)** (4.72)** (1.58)math                     0.520    0.296(7.38)** (3.98)**science                           0.266(4.10)**socst                             0.281(4.83)**Constant       18.162    7.542    2.002(5.49)** (2.31)*  (0.63)Observations    200      200      195R-squared       0.36     0.50     0.58Absolute value of t-statistics in parentheses* significant at 5% level; ** significant at 1% level