<jupyter_start><jupyter_text>Parameters, automated analysis, and prefessional regression tables  Clean your environment<jupyter_code>clear all
set more off<jupyter_output><empty_output><jupyter_text>Import the data<jupyter_code>use "https://github.com/quarcs-lab/data-open/raw/master/auto/regression_auto.dta", clear
describe<jupyter_output>Contains data from https://github.com/quarcs-lab/data-open/raw/master/auto/regre
> ssion_auto.dta
  obs:            26                          
 vars:             8                          21 Mar 2013 20:13
--------------------------------------------------------------------------------
              storage   display    value
variable name   type    format     label      variable label
--------------------------------------------------------------------------------
make            str9    %9s                   make of car
mpg             byte    %8.0g                 miles per gallon
weight          int     %8.0g                 car weight in pounds
weight1         float   %9.0g                 car weight in 1,000 pounds
price           int     %8.0g                 car price in 1978 dollars
foreign         byte    %8.0g                 =1 if car is foreign
repairs         byte    %8.0g                 number of car repairs
length          int     %8.0g                 car length[...]<jupyter_text>Define parameters (list of variables)<jupyter_code>global ylist   mpg
global x1list  weight
global x2list  weight price foreign<jupyter_output><empty_output><jupyter_text>Summarize the data<jupyter_code>sum $ylist $x2list
sum $ylist $x2list, detail<jupyter_output>miles per gallon
-------------------------------------------------------------
      Percentiles      Smallest
 1%           14             14
 5%           14             14
10%           15             15       Obs                  26
25%           17             16       Sum of Wgt.          26

50%           21                      Mean           20.92308
                        Largest       Std. Dev.      4.757504
75%           23             25
90%           26             26       Variance       22.63385
95%           29             29       Skewness       .8806144
99%           35             35       Kurtosis       4.243808

                    car weight in pounds
-------------------------------------------------------------
      Percentiles      Smallest
 1%         2020           2020
 5%         2070           2070
10%         2110           2110       Obs                  26
25%         2640           2230       Sum of Wgt.          26

50%       [...]<jupyter_text>Correlation analysis<jupyter_code>correlate $ylist $x1list
correlate $ylist $x2list<jupyter_output>(obs=26)

             |      mpg   weight    price  foreign
-------------+------------------------------------
         mpg |   1.0000
      weight |  -0.8082   1.0000
       price |  -0.4385   0.5561   1.0000
     foreign |   0.4003  -0.6011   0.0835   1.0000<jupyter_text>Plot and save the data<jupyter_code>graph twoway (scatter $ylist $x1list), name(scatter1, replace)
graph save   "scatter1.gph", replace
graph export "scatter1.png", replace<jupyter_output><empty_output><jupyter_text>Simple regression<jupyter_code>reg $ylist $x1list<jupyter_output>Source |       SS           df       MS      Number of obs   =        26
-------------+----------------------------------   F(1, 24)        =     45.19
       Model |   369.56777         1   369.56777   Prob > F        =    0.0000
    Residual |  196.278384        24  8.17826598   R-squared       =    0.6531
-------------+----------------------------------   Adj R-squared   =    0.6387
       Total |  565.846154        25  22.6338462   Root MSE        =    2.8598

------------------------------------------------------------------------------
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |  -.0055315   .0008229    -6.72   0.000    -.0072298   -.0038332
       _cons |   38.06646   2.611177    14.58   0.000     32.67726    43.45566
------------------------------------------------------------------------------<jupyter_text>Plot a regression line<jupyter_code>graph twoway (scatter $ylist $x1list)(lfit $ylist $x1list), name(linearFit, replace)
graph save   "linearFit.gph", replace
graph export "linearFit.png", replace<jupyter_output><empty_output><jupyter_text>Predict and plot the dependent variable<jupyter_code>quietly reg $ylist $x1list
predict y1hat, xb
summarize $ylist y1hat
graph twoway (scatter $ylist $x1list)(scatter y1hat $x1list), name(predictedValues, replace)
graph save   "predictedValues.gph", replace
graph export "predictedValues.png", replace<jupyter_output>Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         mpg |         26    20.92308    4.757504         14         35
       y1hat |         26    20.92308    3.844829   14.11508   26.89284<jupyter_text>Plot the residuals<jupyter_code>predict e1hat, resid
summarize e1hat
graph twoway (scatter e1hat $x1list), name(residuals, replace)
graph save   "residuals.gph", replace
graph export "residuals.png", replace<jupyter_output>Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
       e1hat |         26    1.60e-08    2.801988  -5.412326   8.107162<jupyter_text>Hypothesis testing<jupyter_code>quietly reg $ylist $x1list
test $x1list
quietly reg $ylist $x2list
test $x2list<jupyter_output>( 1)  weight = 0
 ( 2)  price = 0
 ( 3)  foreign = 0

       F(  3,    22) =   15.25
            Prob > F =    0.0000<jupyter_text>Marginal effects (at the mean and average marginal effect)<jupyter_code>quietly reg $ylist $x1list
margins, dydx(*) atmeans
margins, dydx(*)
quietly reg $ylist $x2list
margins, dydx(*) atmeans
margins, dydx(*)<jupyter_output>Conditional marginal effects                    Number of obs     =         26
Model VCE    : OLS

Expression   : Linear prediction, predict()
dy/dx w.r.t. : weight price foreign
at           : weight          =    3099.231 (mean)
               price           =    6651.731 (mean)
               foreign         =    .2692308 (mean)

------------------------------------------------------------------------------
             |            Delta-method
             |      dy/dx   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |  -.0071211   .0016047    -4.44   0.000     -.010449   -.0037932
       price |   .0002258   .0002654     0.85   0.404    -.0003245    .0007761
     foreign |  -2.507127   2.056568    -1.22   0.236    -6.772188    1.757935
------------------------------------------------------------------------------


Average marginal effects                        Number of obs     =[...]<jupyter_text>Save and export new dataset<jupyter_code>export delimited using "DO_prediction_and_residuals-dat.csv", replace<jupyter_output>file DO_prediction_and_residuals-dat.csv saved<jupyter_text>Build professional regression table You need to install the `outreg2` module first. To install it, type `findit outreg2` in the stata console and follow the instructions<jupyter_code>reg $ylist $x1list, robust
outreg2 using "DO_prediction_and_residuals-tab.xls", replace
reg $ylist $x2list, robust
outreg2 using "DO_prediction_and_residuals-tab.xls", append<jupyter_output>Linear regression                               Number of obs     =         26
                                                F(3, 22)          =      28.79
                                                Prob > F          =     0.0000
                                                R-squared         =     0.6752
                                                Root MSE          =     2.8902

------------------------------------------------------------------------------
             |               Robust
         mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
      weight |  -.0071211   .0010489    -6.79   0.000    -.0092963   -.0049459
       price |   .0002258   .0003421     0.66   0.516    -.0004837    .0009353
     foreign |  -2.507127   2.075987    -1.21   0.240    -6.812459    1.798206
       _cons |    42.1662   2.562411    16.46   0.000     36.85208    47.48031
-------------[...]<jupyter_text>> In your curret directory, you will a `.xls` file that contains your table<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20609812012838147, 'fraction_numerical': 0.09296194406235672, 'mean_word_length': 1.1223546582340063, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 59, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '208210', 'license': 'MIT', 'n_tokens_mistral': 2935, 'n_tokens_neox': 2438, 'n_words': 631, 'path': 'parameters-analysis-tables.ipynb', 'repo_name': 'quaea/margins-interactions', 'size': '8724'}