Announcement

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

  • table for summary statistics, but only for esample() from estimates store

    Is there a way to construct a table of summary statistics for a subset of data using the -table- command? The table command does not accept an if statement.

    Is there any other easy way to construct a table of summary statistics for a subset of data that be exported to an excel file? I would be grateful for some help.

    I am getting the following error:

    table () () (), statistic(mean ESGScFY2019 ESGScFY2020 EnvScFY2019 EnvScFY2020 SocScFY2019 SocScFY2020 GovScFY2019 GovScFY2020 TobinQ2021 TotalCompFY2019 TotalCompLatest TotalCompFY2019 TAFY2019 TAFY2020 Big4 EPSFY2019 EPSFY2020 ROICFY2019 ROICFY2020 OPMFY2019 OPMFY2020 LevFY2019 LevFY2020) if _est_ESGTA==1
    option if not allowed
    r(198);

    Here is a sample of my data:

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte(ESGScFY2019 ESGScFY2020 EnvScFY2019 EnvScFY2020 SocScFY2019 SocScFY2020 GovScFY2019 GovScFY2020) float TobinQ2021 long(TotalCompFY2019 TotalCompLatest) double(TAFY2019 TAFY2020) byte Big4 double(EPSFY2019 EPSFY2020 ROICFY2019) byte _est_ESGTA
     .  .  .  .  .  .  .  .         .       . 1757548         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1533737         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 5246398 2778243         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 2492547 1360000         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 6413945 1055614         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 2987106 1690102         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 2778243 1364863         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1243813         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 1778575 1833639         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 2492547         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 1621173 1778575         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         .  472194 1532258         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1306872         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 2381882 1097858         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 1345079 1372354         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1619916         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 4320442 2924987         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 3550241         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1144867         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 1364863 1770760         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 2808343         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 1727079 6413945         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 1163199 5605968         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 4358946         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 2281928         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 1058830 1345079         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .  561716 1913604         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         . 1432000 3353023         .         . 1       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1293248         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         . 5562828 5659454         .         . 0       .        .         . 0
     .  .  .  .  .  .  .  .         .       . 1395238         .         . 0       .        .         . 0
     0  0  0  0  0  0  0  0         . 1409395 2051222         0         0 0 -.02393  -.01993  -25.5944 0
     0  0  0  0  0  0  0  0         .   93110 2203459         0         0 0 -.02393  -.01993  -25.5944 0
     0  0  0  0  0  0  0  0   3.24244 1025098 1019607    38.474    48.673 0  .16353   .10845   13.3211 1
     0  0  0  0  0  0  0  0 11.742172       . 1490044     5.853     5.388 1  .27176   .22917   12.2434 1
     0  0  0  0  0  0  0  0  3.503915 1161000 1781000   105.883   120.189 0  -.0372  -.05521   -4.5519 1
     0  0  0  0  0  0  0  0  26.13905 1098040 1438723    .71709    12.355 1 -.13112   -.1304  -24.1943 1
     0  0  0  0  0  0  0  0  8.197218 1189325 2783717     111.1     115.7 1  .03262   .19449   -4.4677 1
     0  0  0  0  0  0  0  0  65.94286  333753 2245031  14.03337     5.285 0  .06353   .11729         . 1
     0  0  0  0  0  0  0  0  65.94286       . 1056166  14.03337     5.285 0  .06353   .11729         . 1
     0  0  0  0  0  0  0  0  3408.351       . 1279312         0      .069 0 -.01489  -.00873  -45.5986 0
     0  0  0  0  0  0  0  0   86.0621  453662 1181117     3.654      .808 0 -.09271  -.01769  -29.1718 1
     0  0  0  0  0  0  0  0 4.2968416  670718 1020857         0      .415 0  .02015   .00491         . 0
     0  0  0  0  0  0  0  0 1088.1273 1818423 1114391       1.8       1.9 0  .50376   .35862   19.4151 1
     0  0  0  0  0  0  0  0   23593.3  410291 1126316    .02678    .64184 0 -.03991  -.03427  -93.9212 0
     0  0  0  0  0  0  0  0 25.938923 1993243 1913565   111.395    33.079 1  .08786  -.13045    12.388 1
     0  0  0  0  0  0  0  0 3.8058674  323260 2114697    55.957    63.161 0  .18474   .10263    1.3191 1
     0  0  0  0  0  0  0  0 294.33347 1802530 1298543     2.979     2.695 0  .28201   .23744         . 0
     0  0  0  0  0  0  0  0  4.725979       . 1425316     15.89    10.724 0  -.0447  -.05611  -17.5954 1
     0  0  0  0  0  0  0  0 122.41782 2060568 2218611         0     2.908 0  .29271   .34929    3.7733 1
     0  0  0  0  0  0  0  0 135.47148  705250 2036924    7.2113    6.9664 0 -.22864  -.17011  -67.5996 1
     0  0  0  0  0  0  0  0 2.1731434       . 2708119   145.903       337 0  .19447   .17498    9.9341 1
     0  0  0  0  0  0  0  0 2.1731434 1852857 6634891   145.903       337 0  .19447   .17498    9.9341 1
     0  0  0  0  0  0  0  0 2.1731434 3280577 9343010   145.903       337 0  .19447   .17498    9.9341 1
     0  0  0  0  0  0  0  0  61.22874       . 2193060     7.926     6.823 1 -.01694  -.01388  -52.6074 1
     0  0  0  0  0  0  0  0  77.58294 1677000 2027000     2.834     2.761 1 -.09568  -.02634  -19.4079 0
     0  0  0  0  0  0  0  0  86.25043  926943 1361564         .    .76858 1       .   .02133         . 0
     0  0  0  0  0  0  0  0  3.277082  611218 1221362  59.65535    71.299 0  .00916    .0255    1.4656 1
     0  0  0  0  0  0  0  0 11.882952  498130 1462229     9.809     6.836 0  .03187   .03968    8.7382 1
     0  0  0  0  0  0  0  0 202.06664       . 1082802         0         0 0 -.00095  -.00052 -170.2196 0
     0  0  0  0  0  0  0  0  9.428666  807823 1818881       .32    11.108 1  .06851   .09926   10.2863 1
     0  0  0  0  0  0  0  0         .  169525 1057520         0         0 0 -.00284  -.00187  -10.1437 0
     0  0  0  0  0  0  0  0 1.9538604       . 1106764 107.38376 123.08567 1  .09915    .0721         . 0
     0  0  0  0  0  0  0  0   4.01508       . 1207109 185.42847 341.49874 1  .25672   .11624         . 0
     0  0  0  0  0  0  0  0 122.24294  955177 1647061         0     3.067 0 -.27947  -.11034  -59.2904 1
     0  7  0  7  0  4  0  9  2.811647       . 1233423   372.956   424.731 1  -.2487   .05253  -11.6348 1
    17 20 11 15 13 15 27 31  3.859555       . 2421247     627.7     554.8 1   .0726   .14368   -1.3607 1
     0  8  0  1  0  2  0 20  53.36867   49805 2030267         0  11.95103 0 -.01488        .  -29.1464 0
     0  0  0  0  0  0  0  0  78.41617  207299 4674462   1.49696    1.3936 0 -.05159  -.05158 -270.4106 0
     0  0  0  0  0  0  0  0  6.294841  281402 1091555   1.61829   4.53759 0 -.01465  -.07994   -10.178 0
     0  0  0  0  0  0  0  0 2.0243425  230797 1594610  58.68554     55.06 0 -.02398  -.01669  -12.4638 1
    32 35 27 31 24 30 43 44 4.1224775 2295046 1057299    1780.8    1715.7 1 1.51304 -1.94193     3.059 1
    13 14  0  0  8 10 22 23  9.425321 3781127 4570072    2841.1    3582.9 1 1.09638  2.16045    8.0514 1
    13 14  0  0  8 10 22 23  9.425321       . 4316691    2841.1    3582.9 1 1.09638  2.16045    8.0514 1
    23 27 19 19 18 21 28 37  5.824406 2077176 2645845     780.2    1447.4 1  .31322   .26465     2.965 1
    23 27 19 19 18 21 28 37  5.824406       . 4681078     780.2    1447.4 1  .31322   .26465     2.965 1
    21 26 39 37 15 24 21 25  11.80418 5306544 2487169     545.3     577.5 1  .82557  1.20184    2.5629 1
    21 25 15 27 26 25 23 22 2.0095868 3624994 3097787 10698.067 11553.081 1   .2441   .21928   -1.7573 1
     0  0  0  0  0  0  0  0   2.77983  727129 3068393   200.335   196.712 1  .04085   .02226     .0932 1
    29 27 34 27 20 21 32 32  82.10554       . 2024416        70        60 1  .07433   .05082  -15.5705 0
     0  0  0  0  0  0  0  0  7183.826  249138 1693606         0         0 0  -.0091   -.0137   -9.4571 0
    30 31 53 54 15 14 30 31 2.7368655       . 2958330    3418.9    3829.1 1  .23943   .31538    -.1357 1
     0  0  0  0  0  0  0  0         .       . 1744498         0       .35 1       .  -.03772         . 0
    25 24 22 19 21 15 28 30 1.4232316       . 2191891    5587.8    5531.7 1  .77055   .38138         . 0
     0  0  0  0  0  0  0  0  349.7237  151977 6744694         0    .46294 0 -.01555  -.00468  -22.6085 1
     0  0  0  0  0  0  0  0  4.099734 2197405 2455255   153.665   523.361 1 1.90557  1.72551         . 0
    27 27 27 31 22 21 30 29  48.82791       . 1545193   119.472    113.21 1 3.09155   .86357     4.465 1
     0  0  0  0  0  0  0  0 221.59755  223643 2774702   18.2983  12.23728 1 -.01988  -.01306   -28.315 1
    29 28 26 13 25 19 33 36 1.3190342       . 2966205     12958     12438 1  .74066   .25297         . 0
     0  0  0  0  0  0  0  0  7.858565       . 1204461    23.511    15.639 1  .28329  -.27818   37.4569 1
     0  5  0  0  0  0  0 12 65.003365  115166 3469199         2   4.58894 1 -.07794  -.01444  -38.9851 1
     0  5  0  0  0  0  0 12 65.003365 1196798 2548223         2   4.58894 1 -.07794  -.01444  -38.9851 1
    12 13  1  1  9 10 17 20 24.617867 1092698 2996234     3.139     42.33 1  .15012   .16459    5.6118 1
    72 72 84 78 69 73 67 68  7.693658 2576000 5169000    2200.2    2517.7 1  .92111   .28927   20.2144 1
    72 72 84 78 69 73 67 68  7.693658       . 5826000    2200.2    2517.7 1  .92111   .28927   20.2144 1
     0 10  0  0  0  1  0 19  44.90775       . 1027733         0    44.691 1  .08312   .05024   23.7129 1
    48 59 67 74 36 47 46 60  2.790943 3314527 2595306    1715.3    2835.9 1  .42879  -.26625    1.8318 1
     0  0  0  0  0  0  0  0 304.97574  214412 2787774         0   2.47642 0 -.06216  -.09298  -49.5757 1
    13 17  3 11 12 18 17 19  2.818541 8021058 2394150   479.399     630.9 1  .11263   .20213       5.2 1
    13 17  3 11 12 18 17 19  2.818541       . 1169355   479.399     630.9 1  .11263   .20213       5.2 1
    end



  • #2
    Being careful about the use of Stata terminology pays off. The -if- clause is, in Stata terms, not an option, it is a qualifier. Options come after the comma. The -if- qualifier is part of the main command. All* you need to do to fix this problem is to move it to its proper place, before the comma.

    Code:
    table () () () if _est_ESGTA==1, statistic(mean ESGScFY2019 ESGScFY2020 EnvScFY2019 EnvScFY2020 ///
        SocScFY2019 SocScFY2020 GovScFY2019 GovScFY2020 TobinQ2021 TotalCompFY2019 ///
        TotalCompLatest TotalCompFY2019 TAFY2019 TAFY2020 Big4 EPSFY2019 EPSFY2020 ///
        ROICFY2019)
    I recommend reading the Elements of Stata chapter of the User's Guide [U] volume of the PDF documentation for a review of basic Stata syntax and the associated terminology.


    *Well, I assume that will work in your real data set. In the example the variables ROICFY2020 through LevFY2020 do not exist, so they lead to error messages as well. But I imagine that your real data set has them and they will not be a problem.

    Comment


    • #3
      Dear Prof. Schechter,

      Thank you for the suggestions. Placing the -if- statement before the comma works beautifully!

      I will read Elements of Stata chapter of the User's Guide [U] for basic syntax as you suggest.

      Is there a way to export the results of a pwcorr command in Stata 17?

      Comment


      • #4
        I think I found it a moment ago. Thank you again!

        Comment

        Working...
        X