Announcement

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

  • outreg2 for all dataframes

    Hi,

    I am using Stata 17 and would help in producing tables in all my dataframes. Below is an example of my dataset:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str3 location str7 time float unemp_data byte(pt_output recessions)
    "AUS" "1966-Q3"      1.8 . 1
    "AUS" "1966-Q4"      1.7 . 1
    "AUS" "1967-Q1"      1.8 . 1
    "AUS" "1967-Q2"        2 . 1
    "AUS" "1967-Q3"      1.9 . 1
    "AUS" "1967-Q4"      1.8 . 1
    "AUS" "1968-Q1"      1.9 . 1
    "AUS" "1968-Q2"      1.9 . 1
    "AUS" "1968-Q3"      1.8 . 1
    "AUS" "1968-Q4"      1.7 . 1
    "AUS" "1969-Q1"      1.8 . 1
    "AUS" "1969-Q2"      1.8 . 1
    "AUS" "1969-Q3"      1.7 . 1
    "AUS" "1969-Q4"      1.9 . 1
    "AUS" "1970-Q1"      1.6 . 1
    "AUS" "1970-Q2"      1.7 . 1
    "AUS" "1970-Q3"      1.7 . 1
    "AUS" "1970-Q4"      1.6 . 1
    "AUS" "1971-Q1"      1.7 . 1
    "AUS" "1971-Q2"      1.9 . 1
    "AUS" "1971-Q3"      1.9 1 1
    "AUS" "1971-Q4"      2.2 . 1
    "AUS" "1972-Q1"      2.4 2 1
    "AUS" "1972-Q2"      2.4 . 1
    "AUS" "1972-Q3"      2.9 . 1
    "AUS" "1972-Q4"      2.8 . 1
    "AUS" "1973-Q1"      2.6 . 1
    "AUS" "1973-Q2"      2.3 . 1
    "AUS" "1973-Q3"      2.1 . 1
    "AUS" "1973-Q4"      2.1 . 1
    "AUS" "1974-Q1"      2.1 . 1
    "AUS" "1974-Q2"      2.1 . 1
    "AUS" "1974-Q3"      2.7 . 1
    "AUS" "1974-Q4"        4 . 1
    "AUS" "1975-Q1"      4.8 . 1
    "AUS" "1975-Q2"      4.8 1 1
    "AUS" "1975-Q3"      4.7 . 1
    "AUS" "1975-Q4"      5.4 2 1
    "AUS" "1976-Q1"      4.9 . 1
    "AUS" "1976-Q2"      4.5 . 1
    "AUS" "1976-Q3"      4.8 . 1
    "AUS" "1976-Q4"      4.9 . 1
    "AUS" "1977-Q1"      5.2 . 1
    "AUS" "1977-Q2"      5.6 1 1
    "AUS" "1977-Q3"      5.8 . 1
    "AUS" "1977-Q4"      5.9 2 1
    "AUS" "1978-Q1"      6.6 . 1
    "AUS" "1978-Q2" 6.260822 . 1
    "AUS" "1978-Q3" 6.322245 . 1
    "AUS" "1978-Q4" 6.301046 . 1
    end
    I have used these codes to produce dataframes of all countries and their regressions:

    Code:
    gen quarters = quarterly(time, "yq")
    format quarters %tq
    
    //create dataframes of countries
    ** create all country dataframes with one command
    levelsof location, local(location_list)
    foreach loc of local location_list {
        frame put location time unemp_data pt_output recessions quarters if location=="`loc'", into (`loc'_dataset)
    }
    
    levelsof location, local(location_list)
    foreach loc of local location_list {
        frame `loc'_dataset {
            tsset quarters
            gen P_unemp = unemp[_n+12] - unemp
        }
        
    }
    
    levelsof location, local(location_list)
    foreach loc of local location_list {
        frame `loc'_dataset {
            reg P_unemp unemp
            outreg2 using table_`loc',word
        }
        
    }
    
    
    levelsof location, local(location_list)
    foreach loc of local location_list {
        frame `loc'_dataset {
            sqreg P_unemp unemp , quantiles(0.1 0.5 0.9) reps(200)
            outreg2 using table_`loc'_quantile,word
        }
        
    }

    My intention is to produce word documents for all dataframes. Unfortunately my codes only produce word document of the current frame.

    How does one modify the codes to produce word documents of all dataframes?

    Any help in this area would be appreciated. Thanks!




  • #2
    outreg2 is from SSC, as you are asked to explain. This works in Stata 16.1.

    Code:
    sysuse auto, clear
    regress mpg weight disp
    outreg2 using myfile, word replace
    frame put mpg weight disp gear, into(two)
    frame two{
        regress mpg weight disp gear
        outreg2 using myfile2, word replace
    }
    Res.:

    Code:
    . regress mpg weight disp
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(2, 71)        =     66.79
           Model |  1595.40969         2  797.704846   Prob > F        =    0.0000
        Residual |  848.049768        71  11.9443629   R-squared       =    0.6529
    -------------+----------------------------------   Adj R-squared   =    0.6432
           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4561
    
    ------------------------------------------------------------------------------
             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          weight |  -.0065671   .0011662    -5.63   0.000    -.0088925   -.0042417
    displacement |   .0052808   .0098696     0.54   0.594    -.0143986    .0249602
           _cons |   40.08452    2.02011    19.84   0.000     36.05654    44.11251
    ------------------------------------------------------------------------------
    
    . 
    . outreg2 using myfile.rtf, replace
    myfile.rtf
    dir : seeout
    
    . 
    . frame put mpg weight disp gear, into(two)
    
    . 
    . frame two{
    . 
    .     regress mpg weight disp gear
    
          Source |       SS           df       MS      Number of obs   =        74
    -------------+----------------------------------   F(3, 70)        =     44.05
           Model |  1597.38038         3  532.460128   Prob > F        =    0.0000
        Residual |  846.079075        70  12.0868439   R-squared       =    0.6537
    -------------+----------------------------------   Adj R-squared   =    0.6389
           Total |  2443.45946        73  33.4720474   Root MSE        =    3.4766
    
    ------------------------------------------------------------------------------
             mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
          weight |  -.0065338   .0011761    -5.56   0.000    -.0088794   -.0041882
    displacement |    .007686   .0115781     0.66   0.509    -.0154058    .0307778
      gear_ratio |   .6452576   1.598012     0.40   0.688    -2.541877    3.832392
           _cons |   37.56411   6.564394     5.72   0.000     24.47184    50.65638
    ------------------------------------------------------------------------------
    . 
    .     outreg2 using myfile2.rtf, replace
    myfile2.rtf
    dir : seeout
    . 
    . }
    You can try issuing a version statement at the beginning of the do file

    Code:
    version 16.1

    Comment

    Working...
    X