Announcement

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

  • Table after tuples/forval

    Hello everyone,

    I need to run several regressions using the tuples command:

    Code:
    tuples roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6, min(2) max(2) 
    forval i = 1/`ntuples' {
        probit x1 x2 x3 x4 x5 `tuple`i'' , vce(robust)    
        margins, dydx(*)
    }
    And I need to generate a table presenting the average coefficient obtained, average standard deviation, etc of all these regressions. Additionally, I would like to have a column with the fraction of times a variable was significant (say at 5 or 10%). The problem is I have no idea how to do this.

    If any of you has any idea, I would be much appreciated.

    Best,
    Danielle

  • #2
    There is no machinery in tuples (SSC, as you are asked to explain) or forvalues to do this. So you need something else.

    You want to loop over 28 model fits and record some or possibly all of the estimated parameters and their associated P-values. I don't know what "standard deviation" means here. The standard errors seem likely to be in quite different units. If this were my problem I would use postfile to produce a new dataset but you'll need to look at the documentation of saved results to work out what to post. You'll clearly need to collect all the P-values before you can decide how many of them are less than 0.05 or 0.1.

    Although there are many excellent reporting commands, it seems to me that your need here is for a new dataset of results, not a nicely produced document.


    Comment


    • #3
      Average coefficient of which variable? What does "average standard deviation" even mean? And, important, what version of Stata are you using? If you are using version 16 this is best done with frames, but those aren't available in earlier versions.

      Please post back clarifying. Also, use -dataex- to show example data that code can be tested on. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

      Added: Crossed with #2

      Comment


      • #4
        My apologies for the unclear initial message. You're absolutely right. I will clarify.

        I want to run a probit with combinations of 2 out of 8 variables, roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6, such that:

        Code:
         tuples roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6, min(2) max(2)  
              forval i = 1/`ntuples' {    
              probit x1 x2 x3 x4 x5 `tuple`i'' , vce(robust)        
              margins, dydx(*)
        }
        Essentially, I want to present an output table where all these variables are presented x1 x2 x3 x4 x5 roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6, and gives me the average coefficient of the 28 models, average standard error (sorry that was a typo in the message before, my bad), and especially, a column that states the percentage of times (in the 28 regressions) for which the variable included was significant at a certain threshold.

        Something like this:
        Variable name Average Coefficient across the 28 regression Average St. Error across the 28 regressions Fraction of times the variable was significant
        x1
        x2
        x3
        ...
        roa1
        roa2
        ...
        pp6
        Here follows a sample of my data:

        [CODE]

        Code:
        * Example generated by -dataex-. To install: ssc install dataex
        clear
        input int date double(roa1 roa2 pp1 pp2 pp3 x1 x3)
        15341     .     .                  .    .                  .                  .     .
        15342 29.32 21.12              1.823 3.32              1.637 1.8110000000000004     .
        15343 27.36 19.96 1.7899999999999996 3.31 1.6300000000000003              1.775     .
        15344 26.61 18.73                  .    .                  .                  .     .
        15347 36.66 27.11 1.6799999999999997 3.34 1.5200000000000005 1.6680000000000001     .
        15348 50.97 36.95 1.7480000000000002  3.3 1.5570000000000004 1.7170000000000005     .
        15349 27.02     .                  .    .                  .                  .     .
        15350 57.67 34.12 1.7519999999999998  3.3              1.561 1.7309999999999999     .
        15351 44.79  29.3 1.7320000000000002  3.3 1.5230000000000006 1.7030000000000003     .
        15354 29.03 23.58 1.6390000000000002 3.33 1.4210000000000003 1.5940000000000003     .
        15355 28.39  22.7              1.666 3.32 1.4520000000000004              1.624     .
        15356 29.25 23.45 1.6509999999999998 3.33              1.431 1.6260000000000003     .
        15357 28.65 22.25              1.693 3.32 1.4739999999999998 1.6750000000000003     .
        15358 28.08 22.52 1.7419999999999995 3.31 1.5219999999999998 1.7179999999999995     .
        15361  29.1     . 1.7240000000000002  3.3              1.505 1.6980000000000004     .
        15362 27.62 23.61              2.047 3.03 1.8270000000000004              2.023     .
        15363 26.73 21.88 2.4450000000000003 2.59 2.2279999999999998 2.4299999999999997     .
        15364 24.74 21.15 1.8130000000000002 3.31 1.5740000000000003              1.759     .
        15365 24.07 21.01 1.8930000000000002 3.31 1.6620000000000004 1.8530000000000002     .
        15368 24.41 21.14 1.8830000000000005 3.32 1.6540000000000004              1.839     .
        15369 25.07 24.35 1.8620000000000005 3.32 1.6330000000000005 1.8119999999999998     .
        15370 26.56 23.22 1.8450000000000002 3.32 1.6090000000000004              1.791     .
        15371 25.38 21.09 1.7760000000000002 3.35 1.5550000000000002 1.7360000000000002     .
        15372  24.7 22.71              1.746 3.35 1.5299999999999998 1.7070000000000003     .
        15375 21.25 19.16 1.7440000000000002 3.31 1.5189999999999997              1.698     .
        15376    25 20.07 1.7289999999999996 3.31              1.499 1.6889999999999996     .
        15377 29.86     .                  .    .                  .                  .     .
        15378 40.48 28.96 1.8410000000000002 3.33 1.5969999999999995              1.798     .
        15379 52.88 41.29 1.8529999999999998  3.3 1.6150000000000002 1.8130000000000006     .
        15382  27.5     .                  .    .                  .                  .     .
        15383 36.76 27.46                  . 3.36              1.613              1.799     .
        15384 27.12 20.85 1.9020000000000001  3.3 1.6920000000000002 1.8760000000000003     .
        15385 25.78 21.77 1.8769999999999998 3.29 1.6749999999999998              1.851     .
        15386  26.2 22.37 1.8399999999999999 3.29 1.6340000000000003 1.8090000000000002     .
        15389 26.18     .              1.855 3.28 1.6410000000000005              1.815     .
        15390 28.11 24.43 1.9129999999999998 3.27              1.669              1.847     .
        15391 28.93 22.66              1.979 3.21 1.7409999999999997 1.9139999999999997     .
        15392  27.6  23.8 2.1310000000000002 3.08 1.8970000000000002              2.074     .
        15393 28.82 22.86 1.9389999999999996 3.22              1.701 1.8770000000000002     .
        15396 27.39 21.84              1.892 3.31 1.6560000000000001              1.834     .
        15397 26.76 21.68 1.8800000000000003 3.32               1.65 1.8290000000000002     .
        15398  26.1 21.49 1.8780000000000006 3.32 1.6520000000000006 1.8290000000000002     .
        15399 25.23 21.59 1.8420000000000005 3.34 1.6240000000000006              1.798     .
        15400 24.66 21.34 1.7829999999999995 3.45 1.5590000000000002              1.729     .
        15403 21.06  20.2 1.9460000000000006  3.3 1.7330000000000005 1.9000000000000004     .
        15404 25.45 20.19 2.0090000000000003  3.3              1.787               1.96     .
        15405 26.78 23.37 2.0150000000000006 3.34 1.8010000000000002 1.9740000000000002     .
        15406 43.72 29.42 2.0820000000000003 3.32 1.8560000000000003 2.0320000000000005     .
        15407 24.24     .                  .    .                  .                  .     .
        15410     .     .                  .    .                  .                  .     .
        15411 39.76 28.33 2.0820000000000003 3.32 1.8450000000000002 2.0180000000000002     .
        15412 25.24 19.46 2.1090000000000004 3.28 1.9040000000000004              2.073     .
        15413 23.97  19.2 2.1620000000000004 3.27 1.9499999999999997 2.1149999999999998     .
        15414  22.1 18.42 2.1820000000000004 3.25              1.976 2.1369999999999996     .
        15417 22.05 18.93              2.179 3.23 1.9789999999999996 2.1410000000000005     .
        15418 21.49 18.16 2.2180000000000004 3.19              2.012              2.174     .
        15419 21.97 18.46              2.308 3.12              2.093              2.263     .
        15420  21.5 18.15              2.442 2.99              2.237              2.401     .
        15421 20.29 17.77 2.2010000000000005 3.26 1.9969999999999999 2.1610000000000005     .
        15424 20.53 18.48 2.1580000000000004 3.33 1.9479999999999995 2.1129999999999995     .
        15425 20.12 18.13 2.1020000000000003 3.34              1.899              2.064     .
        15426 19.62  17.7              2.104 3.33 1.8940000000000001 2.0649999999999995     .
        15427 19.52  17.4 2.0689999999999995 3.39 1.8610000000000002              2.036     .
        15428     .     .                  .    .                  .                  .     .
        15431     . 20.45              2.016 3.45              1.806 1.9779999999999998 10847
        15432     . 24.87 2.1519999999999997 3.31 1.9419999999999997 2.1169999999999995 10847
        15433     .  20.5              2.099  3.3 1.9009999999999998              2.077 10847
        15434 21.83 19.78 2.0540000000000003  3.3 1.8410000000000002              2.016 10847
        15435     .     .                  .    .                  .                  . 10847
        15438     .     .                  .    .                  .                  . 10847
        15439 57.42 37.44              2.115 3.29 1.8869999999999996 2.0679999999999996 10847
        15440 60.66 39.46 2.1420000000000003 3.29 1.8970000000000002 2.0759999999999996 10847
        15441 43.36 30.82 2.1079999999999997 3.29              1.862               2.04 10847
        15442 39.48 28.92              2.385 3.01              2.138 2.3150000000000004 10847
        15445 22.28 19.82              2.078 3.27              1.839 2.0100000000000002 10847
        15446 21.53 18.11              2.165 3.26 1.9240000000000004              2.101 10847
        15447 22.51 18.43               2.24  3.2              1.987              2.165 10847
        15448 23.34 19.29              2.246 3.19 2.0109999999999997 2.1830000000000003 10847
        15449 22.17  18.3              2.177 3.27 1.9339999999999997              2.103 10847
        15452 23.08 19.77              2.069 3.33 1.8289999999999997 1.9969999999999999 10847
        15453 23.09 20.28 1.5349999999999997  3.9 1.2900000000000005 1.4630000000000005 10847
        15454 23.15 20.77              2.078 3.31 1.8409999999999997              2.014 10847
        15455 24.75 20.95              2.043  3.3 1.8090000000000002 1.9820000000000002 10847
        15456 24.72 22.14 2.0360000000000005  3.3 1.7919999999999998              1.963 10847
        15459 25.29 24.05              2.077  3.3 1.8340000000000005 2.0060000000000002 10847
        15460 24.85 21.91 2.0000000000000004 3.36              1.762 1.9330000000000003 10645
        15461     .     .                  .    .                  .                  . 10645
        15462     . 25.45              2.128  3.3 1.8810000000000002              2.058 10645
        15463     .  20.3              2.058 3.29 1.8259999999999996 1.9980000000000002 10645
        15466 28.44 22.61              2.019 3.33 1.7850000000000001 1.9589999999999996 10645
        15467 36.76 27.11 2.0240000000000005 3.32 1.7820000000000005 1.9609999999999999 10645
        15468 55.65 45.08 2.1109999999999998  3.3 1.8600000000000003 2.0390000000000006 10645
        15469 55.87 38.86 2.1420000000000003 3.29 1.9029999999999996              2.072 10645
        15470     .     .                  .    .                  .                  . 10645
        15473 25.06 20.72 2.1400000000000006  3.3 1.9020000000000001 2.0730000000000004 10645
        15474 24.98 19.35 2.1900000000000004  3.3 1.9539999999999997              2.127 10645
        15475 24.69 19.19 2.1850000000000005  3.3              1.952 2.1500000000000004 10645
        15476  24.7  18.5              2.173 3.29 1.9480000000000004              2.141 10645
        15477 24.24  17.7 2.2230000000000003 3.27              1.988 2.1839999999999997 10645
        15480 25.27 19.24              2.157 3.26 1.9290000000000003 2.1210000000000004 10645
        end
        format %tdnn/dd/CCYY date
        (I hope this is enough, for some reason my Stata doesn't run if I request more variables on dataex - it's an old computer and it crashes frequently).

        I am using Stata 14.1 on Mac.

        Thank you so much for feedback,

        Danielle

        Comment


        • #5
          #1 implies that x1 is the outcome variable but #4 implies the same -- but also that it is a predictor. Either way, it is not (0, 1) on the evidence here, So I guess you mean something else.

          The coefficient for predictor foo is accessible after the model fit in _b[foo].

          Maarten Buis in https://www.stata-journal.com/articl...article=st0137 gives tips on extracting P-values.

          As in #2 I recommend that it's premature to think of the table you want to see. It's a dataset of results that you need first.

          Comment


          • #6
            Here is some code. As Nick points out, x1 is not a suitable outcome variable for your probit. The code below fills in a new variable z to play that role. Instead you should fix your -probit- command. And, of course, Nick is right: before you can make a table, you need a data set of results.

            Code:
            //  X1 CAN'T BE YOUR DEPENDENT VARIABLE IN A PROBIT: IT ISN'T DICHOTOMOUS
            //  SO I'M FILLING IN A DICHOTOMOUS OUTCOME VARIABLE Z JUST TO ILLUSTRATE\
            //  THE APPROACH.  YOU EVIDENTLY MISTYPED YOUR -probit- COMMAND IN YOUR POST.
            set seed 1234
            gen byte z = runiformint(0, 1)
            
            //  SINCE I DON'T USE -tuples- THIS PART OF THE CODE IS A SUBSTITUTE FOR THAT
            //  YOU CAN JUST USE -tuples- INSTEAD
            local tlist roa1 roa2 pp1 pp2 pp3
            local nvars: word count `tlist'
            local ntuples = 0
            forvalues i = 1/`nvars' {
                forvalues j = `=`i'+1'/`nvars' {
                    local v1: word `i' of `tlist'
                    local v2: word `j' of `tlist'
                    local ++ntuples
                    local tuple`ntuples' `v1' `v2'
                }
            }
            
            
            //    THE CODE YOU WANT BEGINS HERE
            tempfile results
            capture postutil clear
            postfile handle b_x1 se_x1 b_x3 se_x3 b_roa1 se_roa1 b_roa2 se_roa2 b_pp1 se_pp1 ///
                b_pp2 se_pp2 b_pp3 se_pp3 using `results'
                
            forvalues i = 1/`ntuples' {
                display `"`tuple`i''"'
                probit z x1 x3 `tuple`i'', vce(robust)
                local topost (_b[x1]) (_se[x1]) (_b[x3]) (_se[x3])
                foreach v of local tlist {
                    if strpos("`e(cmdline)'", "`v'") {
                        local topost `topost' (_b[`v']) (_se[`v'])
                    }
                    else {
                        local topost `topost' (.) (.)
                    }
                }
                post handle `topost'
                        
            }
            postclose handle
            
            //    LOAD RESULTS AND CALCULATE "SIGNIFICANCE" TEST
            use `results', clear
            
            local critical_value_5 = invnormal(0.975)
            foreach v in x1 x3 `tlist' {
                gen byte sig05_`v' = abs(b_`v'/se_`v') > `critical_value_5' ///
                    if !missing(b_`v', se_`v')
                order sig05_`v', after(se_`v')
            }
            
            //    AGGREGATE UP TO MEANS OVER ALL ANALYSES
            //    THEN MAKE A TABLE
            collapse (mean) _all
            gen one = 1
            reshape long b_ se_ sig05_, i(one) j(varname) string
            rename *_ *
            drop one
            list, noobs clean

            Comment


            • #7
              First of all, thank you so much for the feedback and the code. Indeed, x1 is my dependent variable, and it is not a probit, I'm sorry, but I'm working on several projects and have the bad habit of confusing them all.

              I have a followup question.

              Running Clyde's code but with the reg command instead of probit,

              Code:
                
              tuples roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6, min(2) max(2)        
                 forval i = 1/`ntuples' {          
                 reg x1 x2 x3 x4 x5 `tuple`i'' , vce(robust)              
               }  
              
              
              tempfile results
              capture postutil clear
              postfile handle b_x2 se_x2 b_x3 se_x3 b_roa1 se_roa1 b_roa2 se_roa2 b_pp1 se_pp1 ///    
                           b_pp2 se_pp2 b_pp3 se_pp3 b_pp4 se_pp4 b_pp5 se_pp5 b_pp6 se_pp6 using `results'      
              
              forvalues i = 1/`ntuples' {    
                    display `"`tuple`i''"'    
                   reg x1 x2 x3 x4 x5 `tuple`i'', vce(robust)    
                    local topost (_b[x1]) (_se[x1]) (_b[x2]) (_se[x2]) (_b[x3]) (_se[x3])    
                    
              
              foreach v of local tlist {        
                  if strpos("`e(cmdline)'", "`v'") {            
                   local topost `topost' (_b[`v']) (_se[`v'])
                     }        
                  else {            
                        local topost `topost' (.) (.)
                     }     }    
                       post handle `topost'
                  }
                  postclose handle
              I get the error message:

              Code:
              unknown function ()
              post:  above message corresponds to expression 24, variable se_x2
              x2 is a dummy variable. I don't know if that has anything to do with it.

              (I would post the output tables, but it's 28 regressions, I'm not sure its worth it).

              Any idea?

              Thank you once more,
              Danielle
              Last edited by Danielle Laurie; 11 Oct 2020, 15:27.

              Comment


              • #8
                I believe your error is in
                Code:
                local topost (_b[x1]) (_se[x1]) (_b[x2]) (_se[x2]) (_b[x3]) (_se[x3])
                If x1is your dependent variable, it has no coefficient, nor standard error. So _b[x1] and _se[x1] do not exist. I think if you remove those terms, everything will run.

                Well, also, the -regress- command has to start on a separate line. But I assume that just somehow got mangled when you posted, because if you had it on the same line as the -display- command you wouldn't even have gotten far enough to get the error message you're getting.

                Comment


                • #9
                  That was it yes. Thank you! And yes, reg was on another line, it just deformed when I pasted.

                  Code went a little bit further till it stopped at:

                  Code:
                  local critical_value_5 = invnormal(0.975)
                  foreach v in x2 x3 x4 x5 `tlist' {
                      gen byte sig05_`v' = abs(b_`v'/se_`v') > `critical_value_5' ///
                          if !missing(b_`v', se_`v')    
                      order sig05_`v', after(se_`v')
                  }
                   
                   collapse (mean) _all
                  I get the error:

                  Code:
                   no observations
                  I thought maybe none of my variables was significant at 5% (which is practically impossible in this case but still), so I tried with 10% and 20% and still nothing.

                  Any suggestions?

                  Thank you once again.

                  Comment


                  • #10
                    No, that error message would not come from that, even if that were the case. When I trim out the variables that don't exist in your example data and run the code from #6, modified for x1 to be the dependent variable in a -regress-, I don't encounter this problem:
                    Code:
                    . //  SINCE I DON'T USE -tuples- THIS PART OF THE CODE IS A SUBSTITUTE FOR THAT
                    . //  YOU CAN JUST USE -tuples- INSTEAD
                    . local tlist roa1 roa2 pp1 pp2 pp3
                    
                    . local nvars: word count `tlist'
                    
                    . local ntuples = 0
                    
                    . forvalues i = 1/`nvars' {
                      2.     forvalues j = `=`i'+1'/`nvars' {
                      3.         local v1: word `i' of `tlist'
                      4.         local v2: word `j' of `tlist'
                      5.         local ++ntuples
                      6.         local tuple`ntuples' `v1' `v2'
                      7.     }
                      8. }
                    
                    . 
                    . 
                    . //    THE CODE YOU WANT BEGINS HERE
                    . tempfile results
                    
                    . capture postutil clear
                    
                    . postfile handle b_x3 se_x3 b_roa1 se_roa1 b_roa2 se_roa2 b_pp1 se_pp1 ///
                    >     b_pp2 se_pp2 b_pp3 se_pp3 using `results'
                    
                    .     
                    . forvalues i = 1/`ntuples' {
                      2.     display `"`tuple`i''"'
                      3.     regress x1 x3 `tuple`i'', vce(robust)
                      4.     local topost (_b[x3]) (_se[x3])
                      5.     foreach v of local tlist {
                      6.         if strpos("`e(cmdline)'", "`v'") {
                      7.             local topost `topost' (_b[`v']) (_se[`v'])
                      8.         }
                      9.         else {
                     10.             local topost `topost' (.) (.)
                     11.         }
                     12.     }
                     13.     post handle `topost'
                     14.             
                    . }
                    roa1 roa2
                    
                    Linear regression                               Number of obs     =         27
                                                                    F(3, 23)          =       2.03
                                                                    Prob > F          =     0.1376
                                                                    R-squared         =     0.1316
                                                                    Root MSE          =     .14425
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0001456   .0002403    -0.61   0.550    -.0006428    .0003515
                            roa1 |   .0164621   .0067362     2.44   0.023     .0025272     .030397
                            roa2 |  -.0257206   .0108359    -2.37   0.026    -.0481364   -.0033048
                           _cons |   3.726787   2.555356     1.46   0.158     -1.55937    9.012944
                    ------------------------------------------------------------------------------
                    roa1 pp1
                    
                    Linear regression                               Number of obs     =         27
                                                                    F(3, 23)          =    4476.60
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9932
                                                                    Root MSE          =     .01279
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0000516   .0000261    -1.97   0.061    -.0001056    2.54e-06
                            roa1 |  -.0001879   .0002327    -0.81   0.428    -.0006693    .0002935
                             pp1 |   1.015351   .0092278   110.03   0.000     .9962619     1.03444
                           _cons |   .4672556   .2807684     1.66   0.110    -.1135581    1.048069
                    ------------------------------------------------------------------------------
                    roa1 pp2
                    
                    Linear regression                               Number of obs     =         27
                                                                    F(3, 23)          =     148.05
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.8896
                                                                    Root MSE          =     .05144
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |   -.000195   .0001109    -1.76   0.092    -.0004244    .0000344
                            roa1 |  -.0002417   .0006137    -0.39   0.697    -.0015113    .0010279
                             pp2 |    -1.0053   .0491775   -20.44   0.000    -1.107031   -.9035685
                           _cons |   7.471693   1.213483     6.16   0.000     4.961412    9.981973
                    ------------------------------------------------------------------------------
                    roa1 pp3
                    
                    Linear regression                               Number of obs     =         27
                                                                    F(3, 23)          =    3923.39
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9976
                                                                    Root MSE          =     .00765
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0000335   .0000168    -1.99   0.059    -.0000683    1.35e-06
                            roa1 |  -.0000164   .0001215    -0.13   0.894    -.0002676    .0002349
                             pp3 |     1.0145   .0097965   103.56   0.000     .9942339    1.034765
                           _cons |    .511029   .1792008     2.85   0.009     .1403239    .8817341
                    ------------------------------------------------------------------------------
                    roa2 pp1
                    
                    Linear regression                               Number of obs     =         32
                                                                    F(3, 28)          =    1950.91
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9882
                                                                    Root MSE          =     .01543
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0000186   .0000262    -0.71   0.484    -.0000724    .0000351
                            roa2 |  -.0005574   .0003032    -1.84   0.077    -.0011785    .0000637
                             pp1 |   1.014736   .0135443    74.92   0.000     .9869913     1.04248
                           _cons |      .1241   .2850204     0.44   0.667    -.4597378    .7079378
                    ------------------------------------------------------------------------------
                    roa2 pp2
                    
                    Linear regression                               Number of obs     =         32
                                                                    F(3, 28)          =     369.50
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.8536
                                                                    Root MSE          =     .05431
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0001005   .0001037    -0.97   0.341    -.0003129    .0001119
                            roa2 |  -.0010953   .0009132    -1.20   0.240     -.002966    .0007753
                             pp2 |  -.9800914   .0298497   -32.83   0.000    -1.041236   -.9189471
                           _cons |   6.394332   1.138299     5.62   0.000     4.062632    8.726032
                    ------------------------------------------------------------------------------
                    roa2 pp3
                    
                    Linear regression                               Number of obs     =         32
                                                                    F(3, 28)          =    3820.13
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9975
                                                                    Root MSE          =     .00711
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |   -.000029   .0000145    -2.00   0.055    -.0000586    6.34e-07
                            roa2 |  -.0000922   .0001864    -0.49   0.625    -.0004739    .0002896
                             pp3 |   1.015617   .0099328   102.25   0.000     .9952707    1.035964
                           _cons |   .4615421   .1538218     3.00   0.006     .1464524    .7766318
                    ------------------------------------------------------------------------------
                    pp1 pp2
                    
                    Linear regression                               Number of obs     =         32
                                                                    F(3, 28)          =    1118.82
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9882
                                                                    Root MSE          =     .01541
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0000103   .0000261    -0.40   0.695    -.0000637    .0000431
                             pp1 |   1.094654   .0501288    21.84   0.000     .9919694    1.197338
                             pp2 |    .090515    .052995     1.71   0.099    -.0180404    .1990705
                           _cons |  -.4458095   .3835788    -1.16   0.255    -1.231535     .339916
                    ------------------------------------------------------------------------------
                    pp1 pp3
                    
                    Linear regression                               Number of obs     =         32
                                                                    F(3, 28)          =    3464.39
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9975
                                                                    Root MSE          =     .00708
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0000296   .0000144    -2.05   0.049    -.0000591   -8.00e-08
                             pp1 |  -.0761027   .0548753    -1.39   0.176    -.1885097    .0363043
                             pp3 |    1.09099   .0583881    18.69   0.000     .9713879    1.210593
                           _cons |   .4850285   .1577405     3.07   0.005     .1619118    .8081452
                    ------------------------------------------------------------------------------
                    pp2 pp3
                    
                    Linear regression                               Number of obs     =         32
                                                                    F(3, 28)          =   12712.70
                                                                    Prob > F          =     0.0000
                                                                    R-squared         =     0.9978
                                                                    Root MSE          =     .00665
                    
                    ------------------------------------------------------------------------------
                                 |               Robust
                              x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                    -------------+----------------------------------------------------------------
                              x3 |  -.0000258   .0000126    -2.04   0.051    -.0000516    7.76e-08
                             pp2 |   .0528064   .0259001     2.04   0.051    -.0002475    .1058603
                             pp3 |   1.062619    .026577    39.98   0.000     1.008178    1.117059
                           _cons |   .1622438   .1497062     1.08   0.288    -.1444154    .4689029
                    ------------------------------------------------------------------------------
                    
                    . postclose handle
                    
                    . 
                    . //    LOAD RESULTS AND CALCULATE "SIGNIFICANCE" TEST
                    . use `results', clear
                    
                    . 
                    . local critical_value_5 = invnormal(0.975)
                    
                    . foreach v in x3 `tlist' {
                      2.     gen byte sig05_`v' = abs(b_`v'/se_`v') > `critical_value_5' ///
                    >         if !missing(b_`v', se_`v')
                      3.     order sig05_`v', after(se_`v')
                      4. }
                    (6 missing values generated)
                    (6 missing values generated)
                    (6 missing values generated)
                    (6 missing values generated)
                    (6 missing values generated)
                    
                    . 
                    . //    AGGREGATE UP TO MEANS OVER ALL ANALYSES
                    . //    THEN MAKE A TABLE
                    . collapse (mean) _all
                    
                    . gen one = 1
                    
                    . reshape long b_ se_ sig05_, i(one) j(varname) string
                    (note: j = pp1 pp2 pp3 roa1 roa2 x3)
                    
                    Data                               wide   ->   long
                    -----------------------------------------------------------------------------
                    Number of obs.                        1   ->       6
                    Number of variables                  19   ->       5
                    j variable (6 values)                     ->   varname
                    xij variables:
                                       b_pp1 b_pp2 ... b_x3   ->   b_
                                    se_pp1 se_pp2 ... se_x3   ->   se_
                           sig05_pp1 sig05_pp2 ... sig05_x3   ->   sig05_
                    -----------------------------------------------------------------------------
                    
                    . rename *_ *
                    
                    . drop one
                    
                    . list, noobs clean
                    
                        varname           b         se   sig05  
                            pp1    .7621593    .031944     .75  
                            pp2   -.4605175   .0394806     .75  
                            pp3    1.045931   .0261736       1  
                           roa1     .004004    .001926     .25  
                           roa2   -.0068664   .0030597     .25  
                             x3   -.0000639   .0000592      .5
                    The no observations message, coming at the end, must be arising from the -collapse- command. That implies that in fact nothing ever got posted to `results'. Go back and look at the output of the regress commands from inside the loop. Did the regressions run properly? Do they have the right variables in them? I suspect the "root cause" of the problem is there. But in any case, I can't offer you more specific advice unless you post new example data and the actual code you are running. And be sure to also choose the example data so that it actually reproduces this same error when run with your code.

                    Comment


                    • #11
                      Hello Clyde,

                      Thank you for helping out. The problem is indeed probably there. I wasn't aware that the regressions were supposed to before "post handle topost". Mine just runs the code, and when it reaches to:

                      Code:
                      local critical_value_5 = invnormal(0.975)
                        foreach v in x2 x3 x4 x5 `tlist' {
                           gen byte sig05_`v' = abs(b_`v'/se_`v') > `critical_value_5' ///
                               if !missing(b_`v', se_`v')    
                               order sig05_`v', after(se_`v')
                      }
                      
                      collapse (mean) _all
                      and offers the error:

                      Code:
                      no observations
                      I've tried instead of using tuples to use your code:

                      Code:
                      local tlist roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6
                      local nvars: word count `tlist'
                      local ntuples = 0
                      forvalues i = 1/`nvars' {
                         forvalues j = `=`i'+1'/`nvars' {
                             local v1: word `i' of `tlist'
                             local v2: word `j' of `tlist'
                             local ++ntuples
                             local tuple`ntuples' `v1' `v2'
                          }
                      }
                      and it offers:

                      Code:
                      roa1 pp2
                      Linear regression                               Number of obs     =      4,418
                                                                      F(16, 4401)       =    1467.68
                                                                      Prob > F          =     0.0000
                                                                      R-squared         =     0.8910
                                                                      Root MSE          =     .07776
                      
                      ------------------------------------------------------------------------------
                                   |               Robust
                        x1 |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
                      -------------+----------------------------------------------------------------
                       x2 |   .5689792    .005127   11.98   0.000     .5589276    .5790457
                        x3 |  -.0238799   .0122903    -1.95   0.052    -.0479652    .0002153
                               roa1 |  -.0036278   .0004986    -3.26   0.001    -.0046054   -.0006503
                             pp2 |  -.3359448   .2042147    -1.68   0.093    -.7484662    .0565767
                       _cons |   .1002011   .0175773     5.70   0.000     .0647408    .1344614
                      
                      unknown function ()
                      post:  above message corresponds to expression 14, variable se_x2
                      I would share more data through dataex but I am unsure which segment to chose.
                      Here goes nothing:

                      Code:
                      * Example generated by -dataex-. To install: ssc install dataex
                      clear
                      input int date double(roa1 roa2 pp1 pp2 pp3 x1 x3) byte x2 double(pp4 pp5 pp6)
                      16110     . 16.39 2.2739999999999996 2.02 2.1119999999999997              2.169 4041 0 -.016000000000000014 . 19.666666666666668
                      16111     . 15.94                  .    .                  .                  . 4041 0  -.01499999999999968 . 19.666666666666668
                      16112     . 15.39              2.222 2.06              2.055              2.116 4041 0  -.01499999999999968 . 19.666666666666668
                      16113     . 15.31 2.3930000000000007 1.89              2.229 2.2880000000000003 4041 0  -.01499999999999968 . 19.666666666666668
                      16114 19.02 15.58              2.244 2.02 2.0829999999999997 2.1430000000000002 4041 0 -.016000000000000014 . 19.666666666666668
                      16117 18.37     .              2.256 2.02              2.089 2.1510000000000002 4041 0  -.01499999999999968 . 19.666666666666668
                      16118 18.02  15.4 2.2260000000000004 2.02              2.063 2.1220000000000003 4041 0 -.016000000000000014 . 19.666666666666668
                      16119 17.94 15.59              2.227 2.02               2.06              2.124 4041 0 -.016000000000000014 . 19.666666666666668
                      16120 17.13  15.8              2.259 2.02              2.102              2.166 4041 0  -.01499999999999968 . 19.666666666666668
                      16121 17.96 16.04 2.2560000000000002 2.04 2.0949999999999998 2.1609999999999996 4041 0 -.016000000000000014 . 19.666666666666668
                      16124 18.47 16.29              2.237 2.05 2.0780000000000003              2.144 4041 0 -.015000000000000568 . 19.666666666666668
                      16125 19.47  15.9              2.199 2.05 2.0360000000000005 2.1029999999999998 4041 0  -.01499999999999968 . 19.666666666666668
                      16126 18.81 14.93 2.1900000000000004 2.05              2.032              2.098 4041 0 -.016000000000000014 . 19.666666666666668
                      16127 18.46 14.83                2.2 2.05 2.0380000000000003 2.1050000000000004 4041 0 -.015000000000000568 . 19.666666666666668
                      16128 18.06 14.55               2.15 2.06              1.991 2.0580000000000003 4041 0 -.016000000000000014 . 19.666666666666668
                      16131     . 14.44                  .    .                  .                  . 4008 0 -.015000000000000568 . 19.666666666666668
                      16132 21.35 14.86 2.2080000000000006 2.03 2.0400000000000005 2.1120000000000005 4008 0 -.015000000000000568 . 19.666666666666668
                      16133 17.67 14.55              2.293 1.99               2.13              2.199 4008 0  -.01499999999999968 . 19.666666666666668
                      16134     .  14.4                  .    .                  .                  . 4008 0 -.016000000000000014 . 19.666666666666668
                      16135     . 14.48              2.104 2.04              1.944              2.011 4008 0 -.016000000000000014 . 19.666666666666668
                      16138     . 15.79              2.042 2.05 1.8760000000000003 1.9450000000000003 4008 0 -.015000000000000568 . 19.666666666666668
                      16139     .  16.6              2.064 2.01 1.9000000000000004 1.9700000000000002 4008 0 -.016000000000000014 . 19.666666666666668
                      16140 18.69 18.67                  .    .                  .                  . 4008 0 -.015000000000000568 . 19.666666666666668
                      16141 23.22 20.67 1.9480000000000004 2.13              1.779              1.854 4008 0 -.015000000000000568 . 19.666666666666668
                      16142 24.65  18.3              2.253 1.82 2.0809999999999995               2.16 4008 0  -.01499999999999968 . 19.666666666666668
                      16145 28.77 21.13 2.0370000000000004 2.02 1.8649999999999998              1.951 4008 0  -.01499999999999968 . 19.666666666666668
                      16146 27.89 20.34               2.09 2.01 1.9160000000000004 2.0040000000000004 4008 0 -.015000000000000568 . 19.666666666666668
                      16147 24.41 18.11 2.0520000000000005 2.01 1.8800000000000003 1.9660000000000002 4008 0  -.01499999999999968 . 19.666666666666668
                      16148 26.51 18.53 2.0540000000000003    2              1.884 1.9689999999999999 4008 0  -.01499999999999968 . 19.666666666666668
                      16149    26 19.15              2.066    2              1.891 1.9769999999999999 4008 0  -.01499999999999968 . 19.666666666666668
                      16152 31.74 21.58 2.0330000000000004 2.01 1.8600000000000003 1.9450000000000003 4008 0  -.01499999999999968 . 19.666666666666668
                      16153 29.19 20.67 2.0290000000000004 2.03              1.858              1.943 4008 0  -.01499999999999968 . 19.666666666666668
                      16154 28.37 19.81 1.9809999999999999 2.05               1.81 1.8930000000000002 4008 0  -.01499999999999968 . 19.666666666666668
                      16155 25.92 17.88 1.9699999999999998 2.05 1.7960000000000003              1.879 4008 0  -.01499999999999968 . 19.666666666666668
                      16156 25.05 17.33                  2 2.05 1.8200000000000003 1.9060000000000001 4008 0  -.01499999999999968 . 19.666666666666668
                      16159 22.84  16.5 2.0740000000000003 2.06 1.8940000000000001 1.9810000000000003 4008 0 -.016000000000000014 . 19.666666666666668
                      16160 23.61 16.28 2.0710000000000006 2.05 1.8930000000000002 1.9770000000000003 4008 0  -.01499999999999968 . 19.666666666666668
                      16161 22.67 16.74 2.0450000000000004 2.06              1.871 1.9529999999999998 4031 0 -.015000000000000568 . 19.666666666666668
                      16162 21.71 16.65                  .    .                  .                  . 4031 0  -.01499999999999968 . 19.666666666666668
                      16163 19.04 15.64              2.225 2.03 2.0500000000000003              2.132 4031 0  -.01499999999999968 . 19.666666666666668
                      16166 18.53 14.97              2.232 2.04              2.061 2.1449999999999996 4031 0  -.01499999999999968 . 19.666666666666668
                      16167  20.1 15.32              2.128 2.12 1.9610000000000003               2.04 4031 0  -.01499999999999968 . 19.666666666666668
                      16168 20.76 15.76                  .    .                  .                  . 4031 0  -.01499999999999968 . 19.666666666666668
                      16169 20.58 16.26 2.1850000000000005 2.05              2.018 2.0970000000000004 4031 0 -.016000000000000014 . 19.666666666666668
                      16170     .     .                  .    .                  .                  . 4031 0 -.015000000000000568 . 19.666666666666668
                      16173     . 15.28                  .    .                  .                  . 4031 0 -.016000000000000014 . 19.666666666666668
                      16174 20.84 17.26 2.2699999999999996 2.04              2.104 2.1849999999999996 4031 0  -.01499999999999968 . 19.666666666666668
                      16175 22.03 15.62 2.3010000000000006 2.03 2.1380000000000003 2.2160000000000006 4031 0  -.01499999999999968 . 19.666666666666668
                      16176 22.37 15.74 2.2870000000000004 2.03              2.126              2.203 4031 0 -.016000000000000014 . 19.666666666666668
                      16177 19.56 14.94              2.243 2.03 2.0830000000000006              2.156 4031 0 -.015000000000000568 . 19.666666666666668
                      16180 19.87 15.42 2.2550000000000003 2.02              2.092              2.169 4031 0 -.016000000000000014 . 19.666666666666668
                      16181  19.3 16.67              2.286 2.02              2.131              2.203 4031 0 -.015000000000000568 . 19.666666666666668
                      16182 19.84  15.6 2.3030000000000004 2.02              2.147 2.2159999999999997 4031 0 -.016000000000000014 . 19.666666666666668
                      16183    18 14.61 2.2950000000000004 2.02 2.1430000000000002 2.2129999999999996 4031 0 -.016000000000000014 . 19.666666666666668
                      16184 18.59 14.01              2.313 2.02              2.161              2.233 4031 0 -.016000000000000014 . 19.666666666666668
                      16187  19.5 14.77              2.305 2.03 2.1570000000000005 2.2230000000000003 4031 0  -.01499999999999968 . 19.666666666666668
                      16188 18.93 15.07 2.3060000000000005 2.03 2.1600000000000006 2.2230000000000003 4031 0 -.016000000000000014 . 19.666666666666668
                      16189 21.14 16.29                2.3 2.04 2.1529999999999996 2.2169999999999996 4031 0 -.016000000000000014 . 19.666666666666668
                      16190 22.28  16.6              2.309 2.04 2.1559999999999997 2.2219999999999995 4031 0 -.016000000000000014 . 19.666666666666668
                      16191 22.73 17.19 2.2600000000000002 2.06 2.1149999999999998              2.177 4074 0  -.01499999999999968 . 19.666666666666668
                      16194 22.02 16.62              2.458 1.84 2.3120000000000003               2.37 4074 0 -.016000000000000014 . 19.666666666666668
                      16195 21.83 16.55              2.043 2.26 1.8970000000000002 1.9610000000000003 4074 0 -.016000000000000014 . 19.666666666666668
                      16196 19.88 15.77              2.271 2.04              2.123              2.186 4074 0  -.01499999999999968 . 19.666666666666668
                      16197 22.91 17.05                  .    .                  .                  . 4074 0 -.016000000000000014 . 19.666666666666668
                      16198 22.99 18.13              2.337 2.11 2.1919999999999997 2.2550000000000003 4074 0 -.016000000000000014 . 19.666666666666668
                      16201    26 19.77 2.3320000000000003  2.1 2.1910000000000003              2.251 4074 0 -.016000000000000014 . 19.666666666666668
                      16202 24.04 18.57 2.3120000000000003 2.12 2.1719999999999997 2.2329999999999997 4074 0  -.01499999999999968 . 19.666666666666668
                      16203 25.99 18.14                  .    .                  .                  . 4074 1 -.016000000000000014 . 19.666666666666668
                      16204 25.42 18.86 2.4570000000000003 2.03              2.318 2.3750000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                      16205 25.28 18.47 2.4200000000000004 2.03 2.2790000000000004 2.3350000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                      16208 26.76 19.96              2.384 2.03              2.243              2.299 4074 1  -.01499999999999968 . 19.666666666666668
                      16209 25.34 19.33              2.406 2.03 2.2630000000000003 2.3190000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                      16210 23.29 18.93              2.461 2.02              2.323 2.3770000000000002 4074 1 -.016000000000000014 . 19.666666666666668
                      16211  23.6 18.67              2.445 2.02 2.3080000000000003 2.3640000000000003 4074 1  -.01499999999999968 . 19.666666666666668
                      16212 22.38 18.49              2.424 2.03               2.28 2.3380000000000005 4074 1 -.016000000000000014 . 19.666666666666668
                      16215 24.88 18.08 2.4440000000000004 2.03              2.307              2.363 4074 1 -.016000000000000014 . 19.666666666666668
                      16216 21.35 15.96 2.4310000000000005 2.03 2.2920000000000003 2.3489999999999998 4074 1 -.016000000000000014 . 19.666666666666668
                      16217 21.05 15.97 2.4010000000000002 2.03 2.3000000000000003               2.32 4074 1 -.016000000000000014 . 19.666666666666668
                      16218  20.7 15.28              2.358 2.03              2.254              2.275 4074 1  -.01499999999999968 . 19.666666666666668
                      16219 20.26  15.5 2.3949999999999996 2.04 2.2880000000000003 2.3120000000000003 4074 1 -.016000000000000014 . 19.666666666666668
                      16222 21.23     . 2.4190000000000005 2.05              2.324              2.346 4180 1 -.016000000000000014 . 19.666666666666668
                      16223 22.45  16.3              2.434 2.04 2.3289999999999997 2.3529999999999998 4180 1 -.016000000000000014 . 19.666666666666668
                      16224 20.74 16.08 2.4680000000000004 2.02              2.363              2.389 4180 1 -.016000000000000014 . 19.666666666666668
                      16225 20.76 17.03                  .    .                  .                  . 4180 1 -.016000000000000014 . 19.666666666666668
                      16226 19.33 16.78 1.7489999999999997 2.75 1.6449999999999996 1.6639999999999997 4180 1 -.016000000000000014 . 19.666666666666668
                      16229 19.43 15.39 1.9570000000000003 2.53 1.8530000000000002 1.8729999999999998 4180 1 -.016000000000000014 . 19.666666666666668
                      16230 19.07 15.01              2.537 1.93 2.4350000000000005 2.4540000000000006 4180 1 -.016000000000000014 . 19.666666666666668
                      16231 19.52 15.39 2.3419999999999996 2.16 2.2359999999999998 2.2560000000000002 4180 1 -.016000000000000014 . 19.666666666666668
                      16232 18.41 15.04              2.378 2.13 2.2729999999999997 2.2910000000000004 4180 1 -.016000000000000014 . 19.666666666666668
                      16233 18.17     .                  .    .                  .                  . 4180 1 -.016000000000000014 . 19.666666666666668
                      16236  20.5 16.07 2.4979999999999998 2.03 2.3930000000000002              2.411 4180 1 -.016000000000000014 . 19.666666666666668
                      16237 18.15 15.05 2.4170000000000003 2.03 2.3160000000000003              2.329 4180 1 -.016000000000000014 . 19.666666666666668
                      16238 17.67 14.79              2.448 2.03 2.3430000000000004              2.363 4180 1 -.016000000000000014 . 19.666666666666668
                      16239 18.75 15.15              2.459 2.03              2.355 2.3720000000000003 4180 1 -.016000000000000014 . 19.666666666666668
                      16240 18.18 14.99              2.429 2.03              2.323 2.3380000000000005 4180 1 -.016000000000000014 . 19.666666666666668
                      16243 17.72 15.26              2.414 2.03              2.312              2.328 4180 1 -.016000000000000014 . 19.666666666666668
                      16244  18.8 14.31              2.435 2.03 2.3320000000000003               2.35 4180 1 -.017000000000000348 . 19.666666666666668
                      16245 17.92 13.98 2.4340000000000006 2.03 2.3330000000000006 2.3510000000000004 4180 1 -.016000000000000014 . 19.666666666666668
                      16246 17.83 14.81 2.3700000000000006 2.03 2.2690000000000006              2.286 4180 1 -.016000000000000014 . 19.666666666666668
                      16247 18.11 15.19 2.3869999999999996 2.04              2.285 2.3019999999999996 4180 1 -.016000000000000014 . 19.666666666666668
                      end
                      format %tdnn/dd/CCYY date

                      Thank you once again for your help.

                      Best,
                      ​​​​​​​Danielle

                      Comment


                      • #12
                        Your posts are a little disorganized.
                        Code:
                        local tlist roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6 local nvars: word count `tlist' local ntuples = 0 forvalues i = 1/`nvars' { forvalues j = `=`i'+1'/`nvars' { local v1: word `i' of `tlist' local v2: word `j' of `tlist' local ++ntuples local tuple`ntuples' `v1' `v2' } }
                        and it offers:

                        Code:
                        roa1 pp2 Linear regression Number of obs = 4,418 F(16, 4401) = 1467.68 Prob > F = 0.0000 R-squared = 0.8910 Root MSE = .07776 ------------------------------------------------------------------------------ | Robust x1 | Coef. Std. Err. t P>|t| [95% Conf. Interval] -------------+---------------------------------------------------------------- x2 | .5689792 .005127 11.98 0.000 .5589276 .5790457 x3 | -.0238799 .0122903 -1.95 0.052 -.0479652 .0002153 roa1 | -.0036278 .0004986 -3.26 0.001 -.0046054 -.0006503 pp2 | -.3359448 .2042147 -1.68 0.093 -.7484662 .0565767 _cons | .1002011 .0175773 5.70 0.000 .0647408 .1344614 unknown function () post: above message corresponds to expression 14, variable se_x2
                        is simply not possible because the code shown there doesn't even contain a regression command. You may well be getting that error message when you get to the -post- command, but it isn't coming from that code, it's coming from the block of code with the regression and post commands. In any case, I can't reproduce this error with your example data.

                        But, working with your example data, you have a different problem: your variable pp5 always has missing values. Remember that any regression command excludes from analysis all observations containing a missing value on any variable mentioned in the regression. For any regression involving pp5, that's every single observation. So you are trying to fit a regression to no data. The -regress- command consequently fails and execution stops with a "no observations" error message. Now, I don't know if the missingness of pp5 is an error in your data that you were unaware of and need to fix, or if it is expected that pp5 can be missing, and the example data you showed happens to represent that to the extreme. You should look and see if pp5 is missing throughout your data. If it is, then either there is a problem with how the data set was created, or, if it really is supposed to be missing, it would make sense to remove pp5 from your list of variables.

                        Now, it is often the case that there are missing values scattered around the data set, and sometimes they will accumulate in sufficient numbers in certain situations that a series of regressions will fail at some point due to no observations (or, the closely related error, insufficient observations). For that reason, when writing code that does a series of regressions, it is often a good idea to anticipate that possibility and code in a way that allows the rest of the series to proceed. I have done that in the code below. It runs without any errors in your example data.

                        All of that said, using the data you now show in #11, the following code runs without errors:

                        Code:
                        * Example generated by -dataex-. To install: ssc install dataex
                        clear
                        input int date double(roa1 roa2 pp1 pp2 pp3 x1 x3) byte x2 double(pp4 pp5 pp6)
                        16110     . 16.39 2.2739999999999996 2.02 2.1119999999999997              2.169 4041 0 -.016000000000000014 . 19.666666666666668
                        16111     . 15.94                  .    .                  .                  . 4041 0  -.01499999999999968 . 19.666666666666668
                        16112     . 15.39              2.222 2.06              2.055              2.116 4041 0  -.01499999999999968 . 19.666666666666668
                        16113     . 15.31 2.3930000000000007 1.89              2.229 2.2880000000000003 4041 0  -.01499999999999968 . 19.666666666666668
                        16114 19.02 15.58              2.244 2.02 2.0829999999999997 2.1430000000000002 4041 0 -.016000000000000014 . 19.666666666666668
                        16117 18.37     .              2.256 2.02              2.089 2.1510000000000002 4041 0  -.01499999999999968 . 19.666666666666668
                        16118 18.02  15.4 2.2260000000000004 2.02              2.063 2.1220000000000003 4041 0 -.016000000000000014 . 19.666666666666668
                        16119 17.94 15.59              2.227 2.02               2.06              2.124 4041 0 -.016000000000000014 . 19.666666666666668
                        16120 17.13  15.8              2.259 2.02              2.102              2.166 4041 0  -.01499999999999968 . 19.666666666666668
                        16121 17.96 16.04 2.2560000000000002 2.04 2.0949999999999998 2.1609999999999996 4041 0 -.016000000000000014 . 19.666666666666668
                        16124 18.47 16.29              2.237 2.05 2.0780000000000003              2.144 4041 0 -.015000000000000568 . 19.666666666666668
                        16125 19.47  15.9              2.199 2.05 2.0360000000000005 2.1029999999999998 4041 0  -.01499999999999968 . 19.666666666666668
                        16126 18.81 14.93 2.1900000000000004 2.05              2.032              2.098 4041 0 -.016000000000000014 . 19.666666666666668
                        16127 18.46 14.83                2.2 2.05 2.0380000000000003 2.1050000000000004 4041 0 -.015000000000000568 . 19.666666666666668
                        16128 18.06 14.55               2.15 2.06              1.991 2.0580000000000003 4041 0 -.016000000000000014 . 19.666666666666668
                        16131     . 14.44                  .    .                  .                  . 4008 0 -.015000000000000568 . 19.666666666666668
                        16132 21.35 14.86 2.2080000000000006 2.03 2.0400000000000005 2.1120000000000005 4008 0 -.015000000000000568 . 19.666666666666668
                        16133 17.67 14.55              2.293 1.99               2.13              2.199 4008 0  -.01499999999999968 . 19.666666666666668
                        16134     .  14.4                  .    .                  .                  . 4008 0 -.016000000000000014 . 19.666666666666668
                        16135     . 14.48              2.104 2.04              1.944              2.011 4008 0 -.016000000000000014 . 19.666666666666668
                        16138     . 15.79              2.042 2.05 1.8760000000000003 1.9450000000000003 4008 0 -.015000000000000568 . 19.666666666666668
                        16139     .  16.6              2.064 2.01 1.9000000000000004 1.9700000000000002 4008 0 -.016000000000000014 . 19.666666666666668
                        16140 18.69 18.67                  .    .                  .                  . 4008 0 -.015000000000000568 . 19.666666666666668
                        16141 23.22 20.67 1.9480000000000004 2.13              1.779              1.854 4008 0 -.015000000000000568 . 19.666666666666668
                        16142 24.65  18.3              2.253 1.82 2.0809999999999995               2.16 4008 0  -.01499999999999968 . 19.666666666666668
                        16145 28.77 21.13 2.0370000000000004 2.02 1.8649999999999998              1.951 4008 0  -.01499999999999968 . 19.666666666666668
                        16146 27.89 20.34               2.09 2.01 1.9160000000000004 2.0040000000000004 4008 0 -.015000000000000568 . 19.666666666666668
                        16147 24.41 18.11 2.0520000000000005 2.01 1.8800000000000003 1.9660000000000002 4008 0  -.01499999999999968 . 19.666666666666668
                        16148 26.51 18.53 2.0540000000000003    2              1.884 1.9689999999999999 4008 0  -.01499999999999968 . 19.666666666666668
                        16149    26 19.15              2.066    2              1.891 1.9769999999999999 4008 0  -.01499999999999968 . 19.666666666666668
                        16152 31.74 21.58 2.0330000000000004 2.01 1.8600000000000003 1.9450000000000003 4008 0  -.01499999999999968 . 19.666666666666668
                        16153 29.19 20.67 2.0290000000000004 2.03              1.858              1.943 4008 0  -.01499999999999968 . 19.666666666666668
                        16154 28.37 19.81 1.9809999999999999 2.05               1.81 1.8930000000000002 4008 0  -.01499999999999968 . 19.666666666666668
                        16155 25.92 17.88 1.9699999999999998 2.05 1.7960000000000003              1.879 4008 0  -.01499999999999968 . 19.666666666666668
                        16156 25.05 17.33                  2 2.05 1.8200000000000003 1.9060000000000001 4008 0  -.01499999999999968 . 19.666666666666668
                        16159 22.84  16.5 2.0740000000000003 2.06 1.8940000000000001 1.9810000000000003 4008 0 -.016000000000000014 . 19.666666666666668
                        16160 23.61 16.28 2.0710000000000006 2.05 1.8930000000000002 1.9770000000000003 4008 0  -.01499999999999968 . 19.666666666666668
                        16161 22.67 16.74 2.0450000000000004 2.06              1.871 1.9529999999999998 4031 0 -.015000000000000568 . 19.666666666666668
                        16162 21.71 16.65                  .    .                  .                  . 4031 0  -.01499999999999968 . 19.666666666666668
                        16163 19.04 15.64              2.225 2.03 2.0500000000000003              2.132 4031 0  -.01499999999999968 . 19.666666666666668
                        16166 18.53 14.97              2.232 2.04              2.061 2.1449999999999996 4031 0  -.01499999999999968 . 19.666666666666668
                        16167  20.1 15.32              2.128 2.12 1.9610000000000003               2.04 4031 0  -.01499999999999968 . 19.666666666666668
                        16168 20.76 15.76                  .    .                  .                  . 4031 0  -.01499999999999968 . 19.666666666666668
                        16169 20.58 16.26 2.1850000000000005 2.05              2.018 2.0970000000000004 4031 0 -.016000000000000014 . 19.666666666666668
                        16170     .     .                  .    .                  .                  . 4031 0 -.015000000000000568 . 19.666666666666668
                        16173     . 15.28                  .    .                  .                  . 4031 0 -.016000000000000014 . 19.666666666666668
                        16174 20.84 17.26 2.2699999999999996 2.04              2.104 2.1849999999999996 4031 0  -.01499999999999968 . 19.666666666666668
                        16175 22.03 15.62 2.3010000000000006 2.03 2.1380000000000003 2.2160000000000006 4031 0  -.01499999999999968 . 19.666666666666668
                        16176 22.37 15.74 2.2870000000000004 2.03              2.126              2.203 4031 0 -.016000000000000014 . 19.666666666666668
                        16177 19.56 14.94              2.243 2.03 2.0830000000000006              2.156 4031 0 -.015000000000000568 . 19.666666666666668
                        16180 19.87 15.42 2.2550000000000003 2.02              2.092              2.169 4031 0 -.016000000000000014 . 19.666666666666668
                        16181  19.3 16.67              2.286 2.02              2.131              2.203 4031 0 -.015000000000000568 . 19.666666666666668
                        16182 19.84  15.6 2.3030000000000004 2.02              2.147 2.2159999999999997 4031 0 -.016000000000000014 . 19.666666666666668
                        16183    18 14.61 2.2950000000000004 2.02 2.1430000000000002 2.2129999999999996 4031 0 -.016000000000000014 . 19.666666666666668
                        16184 18.59 14.01              2.313 2.02              2.161              2.233 4031 0 -.016000000000000014 . 19.666666666666668
                        16187  19.5 14.77              2.305 2.03 2.1570000000000005 2.2230000000000003 4031 0  -.01499999999999968 . 19.666666666666668
                        16188 18.93 15.07 2.3060000000000005 2.03 2.1600000000000006 2.2230000000000003 4031 0 -.016000000000000014 . 19.666666666666668
                        16189 21.14 16.29                2.3 2.04 2.1529999999999996 2.2169999999999996 4031 0 -.016000000000000014 . 19.666666666666668
                        16190 22.28  16.6              2.309 2.04 2.1559999999999997 2.2219999999999995 4031 0 -.016000000000000014 . 19.666666666666668
                        16191 22.73 17.19 2.2600000000000002 2.06 2.1149999999999998              2.177 4074 0  -.01499999999999968 . 19.666666666666668
                        16194 22.02 16.62              2.458 1.84 2.3120000000000003               2.37 4074 0 -.016000000000000014 . 19.666666666666668
                        16195 21.83 16.55              2.043 2.26 1.8970000000000002 1.9610000000000003 4074 0 -.016000000000000014 . 19.666666666666668
                        16196 19.88 15.77              2.271 2.04              2.123              2.186 4074 0  -.01499999999999968 . 19.666666666666668
                        16197 22.91 17.05                  .    .                  .                  . 4074 0 -.016000000000000014 . 19.666666666666668
                        16198 22.99 18.13              2.337 2.11 2.1919999999999997 2.2550000000000003 4074 0 -.016000000000000014 . 19.666666666666668
                        16201    26 19.77 2.3320000000000003  2.1 2.1910000000000003              2.251 4074 0 -.016000000000000014 . 19.666666666666668
                        16202 24.04 18.57 2.3120000000000003 2.12 2.1719999999999997 2.2329999999999997 4074 0  -.01499999999999968 . 19.666666666666668
                        16203 25.99 18.14                  .    .                  .                  . 4074 1 -.016000000000000014 . 19.666666666666668
                        16204 25.42 18.86 2.4570000000000003 2.03              2.318 2.3750000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                        16205 25.28 18.47 2.4200000000000004 2.03 2.2790000000000004 2.3350000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                        16208 26.76 19.96              2.384 2.03              2.243              2.299 4074 1  -.01499999999999968 . 19.666666666666668
                        16209 25.34 19.33              2.406 2.03 2.2630000000000003 2.3190000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                        16210 23.29 18.93              2.461 2.02              2.323 2.3770000000000002 4074 1 -.016000000000000014 . 19.666666666666668
                        16211  23.6 18.67              2.445 2.02 2.3080000000000003 2.3640000000000003 4074 1  -.01499999999999968 . 19.666666666666668
                        16212 22.38 18.49              2.424 2.03               2.28 2.3380000000000005 4074 1 -.016000000000000014 . 19.666666666666668
                        16215 24.88 18.08 2.4440000000000004 2.03              2.307              2.363 4074 1 -.016000000000000014 . 19.666666666666668
                        16216 21.35 15.96 2.4310000000000005 2.03 2.2920000000000003 2.3489999999999998 4074 1 -.016000000000000014 . 19.666666666666668
                        16217 21.05 15.97 2.4010000000000002 2.03 2.3000000000000003               2.32 4074 1 -.016000000000000014 . 19.666666666666668
                        16218  20.7 15.28              2.358 2.03              2.254              2.275 4074 1  -.01499999999999968 . 19.666666666666668
                        16219 20.26  15.5 2.3949999999999996 2.04 2.2880000000000003 2.3120000000000003 4074 1 -.016000000000000014 . 19.666666666666668
                        16222 21.23     . 2.4190000000000005 2.05              2.324              2.346 4180 1 -.016000000000000014 . 19.666666666666668
                        16223 22.45  16.3              2.434 2.04 2.3289999999999997 2.3529999999999998 4180 1 -.016000000000000014 . 19.666666666666668
                        16224 20.74 16.08 2.4680000000000004 2.02              2.363              2.389 4180 1 -.016000000000000014 . 19.666666666666668
                        16225 20.76 17.03                  .    .                  .                  . 4180 1 -.016000000000000014 . 19.666666666666668
                        16226 19.33 16.78 1.7489999999999997 2.75 1.6449999999999996 1.6639999999999997 4180 1 -.016000000000000014 . 19.666666666666668
                        16229 19.43 15.39 1.9570000000000003 2.53 1.8530000000000002 1.8729999999999998 4180 1 -.016000000000000014 . 19.666666666666668
                        16230 19.07 15.01              2.537 1.93 2.4350000000000005 2.4540000000000006 4180 1 -.016000000000000014 . 19.666666666666668
                        16231 19.52 15.39 2.3419999999999996 2.16 2.2359999999999998 2.2560000000000002 4180 1 -.016000000000000014 . 19.666666666666668
                        16232 18.41 15.04              2.378 2.13 2.2729999999999997 2.2910000000000004 4180 1 -.016000000000000014 . 19.666666666666668
                        16233 18.17     .                  .    .                  .                  . 4180 1 -.016000000000000014 . 19.666666666666668
                        16236  20.5 16.07 2.4979999999999998 2.03 2.3930000000000002              2.411 4180 1 -.016000000000000014 . 19.666666666666668
                        16237 18.15 15.05 2.4170000000000003 2.03 2.3160000000000003              2.329 4180 1 -.016000000000000014 . 19.666666666666668
                        16238 17.67 14.79              2.448 2.03 2.3430000000000004              2.363 4180 1 -.016000000000000014 . 19.666666666666668
                        16239 18.75 15.15              2.459 2.03              2.355 2.3720000000000003 4180 1 -.016000000000000014 . 19.666666666666668
                        16240 18.18 14.99              2.429 2.03              2.323 2.3380000000000005 4180 1 -.016000000000000014 . 19.666666666666668
                        16243 17.72 15.26              2.414 2.03              2.312              2.328 4180 1 -.016000000000000014 . 19.666666666666668
                        16244  18.8 14.31              2.435 2.03 2.3320000000000003               2.35 4180 1 -.017000000000000348 . 19.666666666666668
                        16245 17.92 13.98 2.4340000000000006 2.03 2.3330000000000006 2.3510000000000004 4180 1 -.016000000000000014 . 19.666666666666668
                        16246 17.83 14.81 2.3700000000000006 2.03 2.2690000000000006              2.286 4180 1 -.016000000000000014 . 19.666666666666668
                        16247 18.11 15.19 2.3869999999999996 2.04              2.285 2.3019999999999996 4180 1 -.016000000000000014 . 19.666666666666668
                        end
                        format %tdnn/dd/CCYY date
                        
                        //  SINCE I DON'T USE -tuples- THIS PART OF THE CODE IS A SUBSTITUTE FOR THAT
                        //  YOU CAN JUST USE -tuples- INSTEAD
                        local tlist roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6
                        
                        local nvars: word count `tlist'
                        
                        local ntuples = 0
                        
                        forvalues i = 1/`nvars' {
                            forvalues j = `=`i'+1'/`nvars' {
                                local v1: word `i' of `tlist'
                                local v2: word `j' of `tlist'
                                local ++ntuples
                                local tuple`ntuples' `v1' `v2'
                            }
                        }
                        
                        
                        
                        //    THE CODE YOU WANT BEGINS HERE
                        tempfile results
                        
                        capture postutil clear
                        
                        postfile handle b_x2 se_x2 b_x3 se_x3 b_roa1 se_roa1 b_roa2 se_roa2 b_pp1 se_pp1 ///
                            b_pp2 se_pp2 b_pp3 se_pp3 b_pp4 se_pp4 b_pp5 se_pp5 b_pp6 se_pp6 using `results'
                        
                            
                        forvalues i = 1/`ntuples' {
                             display `"`tuple`i''"'
                             capture noisily regress x1 x2 x3 `tuple`i'', vce(robust)
                             if c(rc) == 0 {
                                 local topost (_b[x2]) (_se[x2]) (_b[x3]) (_se[x3])
                                 foreach v of local tlist {
                                     if strpos("`e(cmdline)'", "`v'") {
                                         local topost `topost' (_b[`v']) (_se[`v'])
                                     }
                                     else {
                                         local topost `topost' (.) (.)
                                     }
                                 }
                                 post handle `topost'
                             }
                             else if inlist(c(rc), 2000, 2001) { // NO, OR TOO FEW OBSERVATIONS
                                 continue
                             }
                             else { //  REGRESSION FAILED DUE UNEXPECTED PROBLEM: ABORT
                                 display as error "Unexpected error with `tuple`i''"
                                 exit(c(rc))
                             }
                                     
                        }
                        
                        postclose handle
                        
                        //    LOAD RESULTS AND CALCULATE "SIGNIFICANCE" TEST
                        use `results', clear
                        
                        
                        local critical_value_5 = invnormal(0.975)
                        
                        foreach v in x3 `tlist' {
                             gen byte sig05_`v' = abs(b_`v'/se_`v') > `critical_value_5' ///
                                if !missing(b_`v', se_`v')
                            order sig05_`v', after(se_`v')
                        }
                        
                        //    AGGREGATE UP TO MEANS OVER ALL ANALYSES
                        //    THEN MAKE A TABLE
                        collapse (mean) _all
                        
                        gen one = 1
                        
                        reshape long b_ se_ sig05_, i(one) j(varname) string
                        
                        rename *_ *
                        
                        drop one
                        
                        list, noobs clean
                        If any of the regressions fail for a reason other than no or insufficient observation, that will cause execution to halt with an error message. This assures that you are aware of the problem and don't blunder on to produce incomplete and incorrect results.

                        One more thing, although I think you are doing this correctly anyway. This code is meant to be run by copying it into the do-file editor and running it without interruption. Do not attempt to run pieces of this code separately: it relies on local macros that are defined early in the code and used late in the code. If the code is interrupted between macro definition and macro use, the macro goes out of scope (ceases to exist) and that will produce mysterious looking errors. So run the whole thing in one fell swoop.
                        Last edited by Clyde Schechter; 12 Oct 2020, 11:00.

                        Comment


                        • #13
                          Hi Clyde,

                          Thank you for your reply.

                          I've tried running the new code (yes without interruption), both with the tuples and your local tlist initial bit.

                          With the tuples command, it runs one regression of out the combinations and then I get the error message after postclose handle:

                          Code:
                          post:  28 expressions expected and only 15 found
                          Additionally, no b_ se_ variables are created/stored at all.

                          While with the local list command I get the same

                          Code:
                          no observations
                          after the collapse (mean) _all, as before.

                          In this one, the b_ se_ variables are created (and are in the varlist) but when I open the Data Browser, all columns are empty. As you said, it seems that nothing really got posted to 'results'.

                          I find it interesting that not only do I not get an error message for the regressions (they still don't run like yours do after the foreach v of local tlist), but that I get different error messages depending on the initial command, tuples or local tlist.

                          I'm starting to lose hope here. Maybe it's some bug in my post command? I'm unsure what I can do to fix this.

                          Thank you once again,
                          Danielle

                          Comment


                          • #14
                            Look, you are clearly modifying the code from #12 in some way. The error message

                            post: 28 expressions expected and only 15 found
                            is completely impossible with my code because the -postfile- statement calls for 20 expressions, not 28. So you need to show the actual code you are running--the literal exact code you are running--there is no such thing as an unimportant change. And you need to show an example of the data that includes all the variables needed to run that code and reproduce the errors you are getting. I can't troubleshoot imaginary code and I know you are not showing me real code. So set up the example with -dataex- and the code you are using, and then run that code on the example to make sure it illustrates the problem you are having.

                            I do see one clue about the problem from what you have described. You shouldn't be getting different results with my substitute code from what you get with -tuples-. The fact that you are suggests to me that you have not adapted the -local tlist...- command to reflect the full range of variables you want to form pairs from. The -local tlist...- command has to be correct even if you are using -tuples-, because `tlist' is also used later in the code. Crucially, the contents of local macro tlist have to be consistent with, and in the same order as, the variable list in the -postfile- command, except that tlist does not mention x2 or x3. If those don't correspond, the code will fail in various ways.

                            Now, I do notice one error in the code in #12. Where it says -foreach v in x3 `tlist'- it should say -foreach v in x2 x3 `tlist-. But you are not even getting to that part of the code.

                            Comment


                            • #15
                              After some thought, I realized that the code could be modified so that it adapts itself with minimal human intervention to the realities of the data set.

                              Code:
                              * Example generated by -dataex-. To install: ssc install dataex
                              clear
                              input int date double(roa1 roa2 pp1 pp2 pp3 x1 x3) byte x2 double(pp4 pp5 pp6)
                              16110     . 16.39 2.2739999999999996 2.02 2.1119999999999997              2.169 4041 0 -.016000000000000014 . 19.666666666666668
                              16111     . 15.94                  .    .                  .                  . 4041 0  -.01499999999999968 . 19.666666666666668
                              16112     . 15.39              2.222 2.06              2.055              2.116 4041 0  -.01499999999999968 . 19.666666666666668
                              16113     . 15.31 2.3930000000000007 1.89              2.229 2.2880000000000003 4041 0  -.01499999999999968 . 19.666666666666668
                              16114 19.02 15.58              2.244 2.02 2.0829999999999997 2.1430000000000002 4041 0 -.016000000000000014 . 19.666666666666668
                              16117 18.37     .              2.256 2.02              2.089 2.1510000000000002 4041 0  -.01499999999999968 . 19.666666666666668
                              16118 18.02  15.4 2.2260000000000004 2.02              2.063 2.1220000000000003 4041 0 -.016000000000000014 . 19.666666666666668
                              16119 17.94 15.59              2.227 2.02               2.06              2.124 4041 0 -.016000000000000014 . 19.666666666666668
                              16120 17.13  15.8              2.259 2.02              2.102              2.166 4041 0  -.01499999999999968 . 19.666666666666668
                              16121 17.96 16.04 2.2560000000000002 2.04 2.0949999999999998 2.1609999999999996 4041 0 -.016000000000000014 . 19.666666666666668
                              16124 18.47 16.29              2.237 2.05 2.0780000000000003              2.144 4041 0 -.015000000000000568 . 19.666666666666668
                              16125 19.47  15.9              2.199 2.05 2.0360000000000005 2.1029999999999998 4041 0  -.01499999999999968 . 19.666666666666668
                              16126 18.81 14.93 2.1900000000000004 2.05              2.032              2.098 4041 0 -.016000000000000014 . 19.666666666666668
                              16127 18.46 14.83                2.2 2.05 2.0380000000000003 2.1050000000000004 4041 0 -.015000000000000568 . 19.666666666666668
                              16128 18.06 14.55               2.15 2.06              1.991 2.0580000000000003 4041 0 -.016000000000000014 . 19.666666666666668
                              16131     . 14.44                  .    .                  .                  . 4008 0 -.015000000000000568 . 19.666666666666668
                              16132 21.35 14.86 2.2080000000000006 2.03 2.0400000000000005 2.1120000000000005 4008 0 -.015000000000000568 . 19.666666666666668
                              16133 17.67 14.55              2.293 1.99               2.13              2.199 4008 0  -.01499999999999968 . 19.666666666666668
                              16134     .  14.4                  .    .                  .                  . 4008 0 -.016000000000000014 . 19.666666666666668
                              16135     . 14.48              2.104 2.04              1.944              2.011 4008 0 -.016000000000000014 . 19.666666666666668
                              16138     . 15.79              2.042 2.05 1.8760000000000003 1.9450000000000003 4008 0 -.015000000000000568 . 19.666666666666668
                              16139     .  16.6              2.064 2.01 1.9000000000000004 1.9700000000000002 4008 0 -.016000000000000014 . 19.666666666666668
                              16140 18.69 18.67                  .    .                  .                  . 4008 0 -.015000000000000568 . 19.666666666666668
                              16141 23.22 20.67 1.9480000000000004 2.13              1.779              1.854 4008 0 -.015000000000000568 . 19.666666666666668
                              16142 24.65  18.3              2.253 1.82 2.0809999999999995               2.16 4008 0  -.01499999999999968 . 19.666666666666668
                              16145 28.77 21.13 2.0370000000000004 2.02 1.8649999999999998              1.951 4008 0  -.01499999999999968 . 19.666666666666668
                              16146 27.89 20.34               2.09 2.01 1.9160000000000004 2.0040000000000004 4008 0 -.015000000000000568 . 19.666666666666668
                              16147 24.41 18.11 2.0520000000000005 2.01 1.8800000000000003 1.9660000000000002 4008 0  -.01499999999999968 . 19.666666666666668
                              16148 26.51 18.53 2.0540000000000003    2              1.884 1.9689999999999999 4008 0  -.01499999999999968 . 19.666666666666668
                              16149    26 19.15              2.066    2              1.891 1.9769999999999999 4008 0  -.01499999999999968 . 19.666666666666668
                              16152 31.74 21.58 2.0330000000000004 2.01 1.8600000000000003 1.9450000000000003 4008 0  -.01499999999999968 . 19.666666666666668
                              16153 29.19 20.67 2.0290000000000004 2.03              1.858              1.943 4008 0  -.01499999999999968 . 19.666666666666668
                              16154 28.37 19.81 1.9809999999999999 2.05               1.81 1.8930000000000002 4008 0  -.01499999999999968 . 19.666666666666668
                              16155 25.92 17.88 1.9699999999999998 2.05 1.7960000000000003              1.879 4008 0  -.01499999999999968 . 19.666666666666668
                              16156 25.05 17.33                  2 2.05 1.8200000000000003 1.9060000000000001 4008 0  -.01499999999999968 . 19.666666666666668
                              16159 22.84  16.5 2.0740000000000003 2.06 1.8940000000000001 1.9810000000000003 4008 0 -.016000000000000014 . 19.666666666666668
                              16160 23.61 16.28 2.0710000000000006 2.05 1.8930000000000002 1.9770000000000003 4008 0  -.01499999999999968 . 19.666666666666668
                              16161 22.67 16.74 2.0450000000000004 2.06              1.871 1.9529999999999998 4031 0 -.015000000000000568 . 19.666666666666668
                              16162 21.71 16.65                  .    .                  .                  . 4031 0  -.01499999999999968 . 19.666666666666668
                              16163 19.04 15.64              2.225 2.03 2.0500000000000003              2.132 4031 0  -.01499999999999968 . 19.666666666666668
                              16166 18.53 14.97              2.232 2.04              2.061 2.1449999999999996 4031 0  -.01499999999999968 . 19.666666666666668
                              16167  20.1 15.32              2.128 2.12 1.9610000000000003               2.04 4031 0  -.01499999999999968 . 19.666666666666668
                              16168 20.76 15.76                  .    .                  .                  . 4031 0  -.01499999999999968 . 19.666666666666668
                              16169 20.58 16.26 2.1850000000000005 2.05              2.018 2.0970000000000004 4031 0 -.016000000000000014 . 19.666666666666668
                              16170     .     .                  .    .                  .                  . 4031 0 -.015000000000000568 . 19.666666666666668
                              16173     . 15.28                  .    .                  .                  . 4031 0 -.016000000000000014 . 19.666666666666668
                              16174 20.84 17.26 2.2699999999999996 2.04              2.104 2.1849999999999996 4031 0  -.01499999999999968 . 19.666666666666668
                              16175 22.03 15.62 2.3010000000000006 2.03 2.1380000000000003 2.2160000000000006 4031 0  -.01499999999999968 . 19.666666666666668
                              16176 22.37 15.74 2.2870000000000004 2.03              2.126              2.203 4031 0 -.016000000000000014 . 19.666666666666668
                              16177 19.56 14.94              2.243 2.03 2.0830000000000006              2.156 4031 0 -.015000000000000568 . 19.666666666666668
                              16180 19.87 15.42 2.2550000000000003 2.02              2.092              2.169 4031 0 -.016000000000000014 . 19.666666666666668
                              16181  19.3 16.67              2.286 2.02              2.131              2.203 4031 0 -.015000000000000568 . 19.666666666666668
                              16182 19.84  15.6 2.3030000000000004 2.02              2.147 2.2159999999999997 4031 0 -.016000000000000014 . 19.666666666666668
                              16183    18 14.61 2.2950000000000004 2.02 2.1430000000000002 2.2129999999999996 4031 0 -.016000000000000014 . 19.666666666666668
                              16184 18.59 14.01              2.313 2.02              2.161              2.233 4031 0 -.016000000000000014 . 19.666666666666668
                              16187  19.5 14.77              2.305 2.03 2.1570000000000005 2.2230000000000003 4031 0  -.01499999999999968 . 19.666666666666668
                              16188 18.93 15.07 2.3060000000000005 2.03 2.1600000000000006 2.2230000000000003 4031 0 -.016000000000000014 . 19.666666666666668
                              16189 21.14 16.29                2.3 2.04 2.1529999999999996 2.2169999999999996 4031 0 -.016000000000000014 . 19.666666666666668
                              16190 22.28  16.6              2.309 2.04 2.1559999999999997 2.2219999999999995 4031 0 -.016000000000000014 . 19.666666666666668
                              16191 22.73 17.19 2.2600000000000002 2.06 2.1149999999999998              2.177 4074 0  -.01499999999999968 . 19.666666666666668
                              16194 22.02 16.62              2.458 1.84 2.3120000000000003               2.37 4074 0 -.016000000000000014 . 19.666666666666668
                              16195 21.83 16.55              2.043 2.26 1.8970000000000002 1.9610000000000003 4074 0 -.016000000000000014 . 19.666666666666668
                              16196 19.88 15.77              2.271 2.04              2.123              2.186 4074 0  -.01499999999999968 . 19.666666666666668
                              16197 22.91 17.05                  .    .                  .                  . 4074 0 -.016000000000000014 . 19.666666666666668
                              16198 22.99 18.13              2.337 2.11 2.1919999999999997 2.2550000000000003 4074 0 -.016000000000000014 . 19.666666666666668
                              16201    26 19.77 2.3320000000000003  2.1 2.1910000000000003              2.251 4074 0 -.016000000000000014 . 19.666666666666668
                              16202 24.04 18.57 2.3120000000000003 2.12 2.1719999999999997 2.2329999999999997 4074 0  -.01499999999999968 . 19.666666666666668
                              16203 25.99 18.14                  .    .                  .                  . 4074 1 -.016000000000000014 . 19.666666666666668
                              16204 25.42 18.86 2.4570000000000003 2.03              2.318 2.3750000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                              16205 25.28 18.47 2.4200000000000004 2.03 2.2790000000000004 2.3350000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                              16208 26.76 19.96              2.384 2.03              2.243              2.299 4074 1  -.01499999999999968 . 19.666666666666668
                              16209 25.34 19.33              2.406 2.03 2.2630000000000003 2.3190000000000004 4074 1 -.016000000000000014 . 19.666666666666668
                              16210 23.29 18.93              2.461 2.02              2.323 2.3770000000000002 4074 1 -.016000000000000014 . 19.666666666666668
                              16211  23.6 18.67              2.445 2.02 2.3080000000000003 2.3640000000000003 4074 1  -.01499999999999968 . 19.666666666666668
                              16212 22.38 18.49              2.424 2.03               2.28 2.3380000000000005 4074 1 -.016000000000000014 . 19.666666666666668
                              16215 24.88 18.08 2.4440000000000004 2.03              2.307              2.363 4074 1 -.016000000000000014 . 19.666666666666668
                              16216 21.35 15.96 2.4310000000000005 2.03 2.2920000000000003 2.3489999999999998 4074 1 -.016000000000000014 . 19.666666666666668
                              16217 21.05 15.97 2.4010000000000002 2.03 2.3000000000000003               2.32 4074 1 -.016000000000000014 . 19.666666666666668
                              16218  20.7 15.28              2.358 2.03              2.254              2.275 4074 1  -.01499999999999968 . 19.666666666666668
                              16219 20.26  15.5 2.3949999999999996 2.04 2.2880000000000003 2.3120000000000003 4074 1 -.016000000000000014 . 19.666666666666668
                              16222 21.23     . 2.4190000000000005 2.05              2.324              2.346 4180 1 -.016000000000000014 . 19.666666666666668
                              16223 22.45  16.3              2.434 2.04 2.3289999999999997 2.3529999999999998 4180 1 -.016000000000000014 . 19.666666666666668
                              16224 20.74 16.08 2.4680000000000004 2.02              2.363              2.389 4180 1 -.016000000000000014 . 19.666666666666668
                              16225 20.76 17.03                  .    .                  .                  . 4180 1 -.016000000000000014 . 19.666666666666668
                              16226 19.33 16.78 1.7489999999999997 2.75 1.6449999999999996 1.6639999999999997 4180 1 -.016000000000000014 . 19.666666666666668
                              16229 19.43 15.39 1.9570000000000003 2.53 1.8530000000000002 1.8729999999999998 4180 1 -.016000000000000014 . 19.666666666666668
                              16230 19.07 15.01              2.537 1.93 2.4350000000000005 2.4540000000000006 4180 1 -.016000000000000014 . 19.666666666666668
                              16231 19.52 15.39 2.3419999999999996 2.16 2.2359999999999998 2.2560000000000002 4180 1 -.016000000000000014 . 19.666666666666668
                              16232 18.41 15.04              2.378 2.13 2.2729999999999997 2.2910000000000004 4180 1 -.016000000000000014 . 19.666666666666668
                              16233 18.17     .                  .    .                  .                  . 4180 1 -.016000000000000014 . 19.666666666666668
                              16236  20.5 16.07 2.4979999999999998 2.03 2.3930000000000002              2.411 4180 1 -.016000000000000014 . 19.666666666666668
                              16237 18.15 15.05 2.4170000000000003 2.03 2.3160000000000003              2.329 4180 1 -.016000000000000014 . 19.666666666666668
                              16238 17.67 14.79              2.448 2.03 2.3430000000000004              2.363 4180 1 -.016000000000000014 . 19.666666666666668
                              16239 18.75 15.15              2.459 2.03              2.355 2.3720000000000003 4180 1 -.016000000000000014 . 19.666666666666668
                              16240 18.18 14.99              2.429 2.03              2.323 2.3380000000000005 4180 1 -.016000000000000014 . 19.666666666666668
                              16243 17.72 15.26              2.414 2.03              2.312              2.328 4180 1 -.016000000000000014 . 19.666666666666668
                              16244  18.8 14.31              2.435 2.03 2.3320000000000003               2.35 4180 1 -.017000000000000348 . 19.666666666666668
                              16245 17.92 13.98 2.4340000000000006 2.03 2.3330000000000006 2.3510000000000004 4180 1 -.016000000000000014 . 19.666666666666668
                              16246 17.83 14.81 2.3700000000000006 2.03 2.2690000000000006              2.286 4180 1 -.016000000000000014 . 19.666666666666668
                              16247 18.11 15.19 2.3869999999999996 2.04              2.285 2.3019999999999996 4180 1 -.016000000000000014 . 19.666666666666668
                              end
                              format %tdnn/dd/CCYY date
                              
                              //  CREATE VARIABLE LISTS
                              local dvar x1   // DEPENDENT VARIABLE
                              local always_vars x2 x3 //  INDEPENDENT VARIABLES APPEARING IN ALL REGRESSIONS
                              local tlist roa1 roa2 pp1 pp2 pp3 pp4 pp5 pp6  // VARIABLES FOR TUPLES
                              
                              //  SINCE I DON'T USE -tuples- THIS PART OF THE CODE IS A SUBSTITUTE FOR THAT
                              //  YOU CAN JUST USE -tuples- INSTEAD
                              
                              local nvars: word count `tlist'
                              
                              local ntuples = 0
                              
                              forvalues i = 1/`nvars' {
                                  forvalues j = `=`i'+1'/`nvars' {
                                      local v1: word `i' of `tlist'
                                      local v2: word `j' of `tlist'
                                      local ++ntuples
                                      local tuple`ntuples' `v1' `v2'
                                  }
                              }
                              
                              
                              
                              //    THE CODE YOU WANT BEGINS HERE
                              tempfile results
                              
                              capture postutil clear
                              
                              local results_vars
                              foreach v of varlist `always_vars' `tlist' {
                                  local results_vars `results_vars' b_`v' se_`v'
                              }
                              
                              local initial
                              foreach v of varlist `always_vars' {
                                  local initial `initial' (_b[`v']) (_se[`v'])
                              }
                              
                              postfile handle `results_vars' using `results'
                              
                                  
                              forvalues i = 1/`ntuples' {
                                   display `"`tuple`i''"'
                                   capture noisily regress `dvar' `always_vars' `tuple`i'', vce(robust)
                                   if c(rc) == 0 {
                                       local topost `initial'
                                       foreach v of local tlist {
                                           if strpos("`e(cmdline)'", "`v'") {
                                               local topost `topost' (_b[`v']) (_se[`v'])
                                           }
                                           else {
                                               local topost `topost' (.) (.)
                                           }
                                       }
                                       post handle `topost'
                                   }
                                   else if inlist(c(rc), 2000, 2001) { // NO, OR TOO FEW OBSERVATIONS
                                       continue
                                   }
                                   else { //  REGRESSION FAILED DUE UNEXPECTED PROBLEM: ABORT
                                       display as error "Unexpected error with `tuple`i''"
                                       exit(c(rc))
                                   }
                                           
                              }
                              
                              postclose handle
                              
                              //    LOAD RESULTS AND CALCULATE "SIGNIFICANCE" TEST
                              use `results', clear
                              
                              
                              local critical_value_5 = invnormal(0.975)
                              
                              foreach v in `always_vars' `tlist' {
                                   gen byte sig05_`v' = abs(b_`v'/se_`v') > `critical_value_5' ///
                                      if !missing(b_`v', se_`v')
                                  order sig05_`v', after(se_`v')
                              }
                              
                              //    AGGREGATE UP TO MEANS OVER ALL ANALYSES
                              //    THEN MAKE A TABLE
                              collapse (mean) _all
                              
                              gen one = 1
                              
                              reshape long b_ se_ sig05_, i(one) j(varname) string
                              
                              rename *_ *
                              
                              drop one
                              
                              list, noobs clean
                              All you need to do is change the contents of the local macros dvar, always_vars, and tlist (see the part of the code in red above) so that they contain, respectively, the one variable that is the dependent variable in all the regressions (which, so far has been x1), the list of variables that appear in every regression as a predictor (which, so far, has been variously x2 and x3, or just x3), and the variables that get put together in pairs (which, so far have been roa1, roa2, and an assortment of pp# variables). Just set those variable lists, and the code will then fill in the appropriate variables in the places they are needed. That we you are assured that the variables in the results postfile will correspond correctly to the variables in the regressions.

                              Comment

                              Working...
                              X