benjann / estout

Stata module to make regression tables
http://repec.sowi.unibe.ch/stata/estout/index.html
MIT License
71 stars 18 forks source link

cannot treat `indicate()` option correctly if use `order()` & `unstack` option simultaneously #33

Closed dreistein543 closed 2 years ago

dreistein543 commented 2 years ago

The estout packge is amazing and it helps me a lot when I doing my research.

however, when I try to output my analysis result computed by regress & ivprobit with mle estimation, something occurs.

it is because esttab cannot ouput r-square for the first-step result of ivporbit (p.s. mle estimation does not use two-step but the usage of "first-step" makes my issue more clearly and simply), I put a regression of first-step manually and try to out put them together use esttab.

however, when I use indicate order and unstack simultaneously, all Factor variables display "No". If I use them separately, the result displays well.

I will show you my commands and a sample of my data to ensure the problem replication.

command I use list as follows

ssc install estout, replace
version 16.1
reg X IV c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 i.f1 i.f2 i.f3, cluster(id) 
est store m1
ivprobit Y (X = IV) c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 i.f1 i.f2 i.f3 , vce(cluster id) nolog
est store m2
* if not specify unstack or order, result display correctly
esttab m1 m2, order(X IV) i("F1 = *.f1" "F2 = *.f2" "F3 = *.f3") star (* 0.1 ** 0.05 *** 0.01) b(3) ar2(3) pr2(3) se(3) compress nogap
esttab m1 m2, unstack i("F1 = *.f1" "F2 = *.f2" "F3 = *.f3") star (* 0.1 ** 0.05 *** 0.01) b(3) ar2(3) pr2(3) se(3) compress nogap
* if specify unstack with order, result display uncorrectly
esttab m1 m2, order(X IV) i("F1 = *.f1" "F2 = *.f2" "F3 = *.f3")  unstack star (* 0.1 ** 0.05 *** 0.01) b(3) ar2(3) pr2(3) se(3) compress nogap

sample of my data as follows

* Example generated by -dataex-. For more info, type help dataex
clear
input byte Y float X byte IV float(c1 c2) double(c3 c4 c5) byte c6 float c7 byte c8 float c9 byte c10 double c11 int f1 byte(f2 f3) long id
0            0 1  23.46837   .006541886  .584785 .259396  .945744 1 21.9283  7  .4285714 0    -.11655366675306045 2019 10 2      6
1      .931652 1  23.19192     .0186401   .78998 .063562  .754897 0 34.3563  9  .3333333 0      .1977455340583456 2018  5 1     18
0            0 1  26.02094  -.001736022  .771622 .156775 1.060117 1 49.2763 11  .3636364 0   -.010866227145588936 2020 10 4     31
0            0 1 23.016335   .012496668  .474905 .233348  .689768 0 31.2136 11  .3636364 0    .005297819125023917 2018 10 1     36
0     .6864821 1  21.87479   .017915009  .096148 .342849  .665288 0  21.424  6        .5 1     .27582669998569753 2020 11 2     38
0            1 0 23.573277   .002382931  .365806 .487525  .900957 0 30.9812 11  .3636364 1    -.17572801194276777 2016 10 4     40
1      .981386 1  23.30763  -.005051685  .561924 .009116 1.071822 0 21.6015  9  .3333333 0     -.6148126419216235 2018 10 4     56
0            0 1 26.018044    .01091604   .69921 .126205  .977708 1 24.2327 15  .3333333 1    -.07596493372714253 2018  3 3    338
0     .6569666 0  21.51874   .013169032  .687026 .093621  .556728 1  31.787  9  .3333333 0    -.11737896775579348 2017 13 2    430
1            1 0  22.42486   .010241698  .339621 .440422  .431784 0 18.8779 11  .3636364 0                      0 2017  6 2    516
1     .4899617 1 23.288143   -.01749491  .560025 .056537  .436076 0 29.7449  9  .3333333 0     -.6006745103969204 2021 16 3    516
0            0 0  22.40464   .012537514  .370047 .082347   .74342 1 19.9556  9  .3333333 0    -.11634206159438198 2017  3 2    530
0            0 0 21.560545   .018766297  .334181 .262158  .497236 1  30.312  8      .375 0    -.11668189565184095 2016  7 2    548
1     .9116874 1 21.246815  -.003457195  .344483 .024151  .612639 0 40.9405  9  .3333333 0    -.07784820660390424 2018  4 1    593
1      .986315 1  23.31573  -.004962781  .783798 .094795  .931482 0 37.0361  9  .3333333 0    .013097731488616926 2019 10 3    615
0            0 1 25.332537  .0025077634  .530055 .236704 1.062829 1 21.5571 14  .5714286 0   -.024067825172208845 2018  3 2    625
1     .9999999 1 26.296926   .008612957  .844228 .123185 1.064735 0 18.0372 11  .3636364 1     .04479371502954366 2018 10 4    671
0            0 1 20.553326  .0045889206  .193143 .115185  .302466 0 23.1487  9  .3333333 0 -5.396414033298491e-06 2020  3 2    677
0            0 0  22.95249  .0009692671  .613174 .135704  .760235 1 27.6248  9  .3333333 0    -.07122257922276476 2017  3 3    680
0     .7369868 1  23.90527    .01221528  .509455 .057126 1.062701 0 33.6992 12  .3333333 0    -.13049502926040724 2019  3 2    683
0            0 1 20.837915    -.1182104  .572671 .113313  .578655 1 25.1346  7  .4285714 0    -.07392728860584852 2021  3 2    702
0            0 1 21.568424  .0088016745  .351822 .083551  .832347 1 19.9411  8      .375 1    -.07400341192740123 2019  6 3    705
0            0 0 22.408474    .01693302  .336944 .068215  .787301 1 29.9549  9  .3333333 0     .10766481792697169 2016  3 2    708
1            1 0  20.48228  -.019285915   .41808 .050187  .393641 0  29.728  9  .3333333 0     -.6350792050361633 2015  3 3    723
0           .5 0  24.17106 -.0005589074  .421673 .044988  1.03649 1 24.5133  9  .3333333 0    .062074019290166316 2016  3 3    727
1            1 1  26.21689   .007330722  .868842 .047537 1.063074 0 48.9695  7  .4285714 1     .18378027834930188 2018 10 4    732
1            1 0 22.488445   .007887862   .37082 .143391  .643284 0 17.1438  7  .4285714 0    -.08303293121949185 2017  1 2    735
1            0 1 22.163485    .04025276   .41607 .060288  .526782 0 28.7391  9  .3333333 0    -.08435569512274099 2018  3 4    818
1            0 1 24.283895   .008866069  .563923 .108443  .755345 1 16.5631  9  .3333333 0    -.11185501474792003 2018 13 1    826
1     .9563587 0  21.04916   .005275281  .723027 .044186   .34623 0      16 12  .3333333 0    -.00932005846570827 2017  3 2    835
0            0 1  23.91804   .012171192  .728021 .084915  .935231 1 63.7759  9  .3333333 0    -.05721366980782239 2018  3 3    951
0     .9921135 0  21.99486   .003200878  .045888  .21997  .410353 0 15.5054 11  .3636364 0    -.03620999534668101 2016  9 3    971
0     .7076803 1 23.249954   .027880866  .170929 .019767  .491508 0 15.7377  9  .3333333 0    -.14603524429220283 2020  2 2    975
0            0 0  21.70412   -.03122518  .425738 .042634  .509971 1      16 15  .3333333 0    -.04114783133753397 2016 13 4    978
0     .4118111 1 23.228773   .006608562   .48451 .168233  .553162 0 29.5884  5        .4 1    -.10578884623808715 2019  9 4    997
0    .11145928 1   21.9399   .028344434  .208003 .294275  .644397 0 33.7485  9  .3333333 0    -.05498129542436203 2021  3 1   2026
1            0 1  23.49621   .009799164  .420781 .110208  .589225 0 20.4132 11  .4545455 0    -.13643013622435207 2018  9 4   2065
1      .995297 0  21.84675   .020259835  .645872 .056661  .430803 0 34.8472  8      .375 0    -.11498395856922006 2017 17 2   2071
1     .7691944 0 21.517035   .005613637  .525038 .049952  .559337 0 33.1068  7  .4285714 0     -.2073176004196866 2017  3 4   2076
0     .5726156 0 23.735254   .011374236  .619114 .060514  .815505 0 55.8754  7  .4285714 1    .022001220513940156 2016  3 2   2078
1            1 0 22.010984   .000543693  .218926 .115767  .603424 0 35.1898  9  .3333333 1      -.275883887212102 2016  1 1   2086
1     .9991736 1 22.128185  .0007240294  .264203 .086587  .676367 0 27.9192  9  .3333333 1     -.3023150080763912 2018  1 1   2086
1     .9998389 0  22.21816    .07421203  .386889 .157778  .468513 0 22.1626  7  .4285714 0    -.19427643826624996 2017  3 2   2094
1     .9974306 0  22.72781   .009052862  .682001 .058711  .708496 0 41.0186  9  .3333333 1    -.44110169842582236 2015  3 3   2121
1     .9784886 0  23.41279   .006868779    .6801 .119318  .799269 0 43.1582  9  .3333333 1    -.05238845983289375 2017  3 2   2121
1     .9647424 0 23.457254   .007575728   .68176 .087537  .799617 0 43.1362  9  .3333333 1    -.10116164811614736 2017  3 4   2121
1     .4627682 0 22.515156   .006606665  .546047 .076851   .60711 0 24.4453  7  .4285714 0     .07938299075279942 2017  3 2   2130
0 .00005696172 1  24.14001   .010082267  .638599 .091504  .738933 0   34.48  9  .3333333 1     .01651840290691542 2021  3 3   2203
0     .3630657 1 20.956406   .006260512  .372676 .050175  .405019 0 38.2124  5        .5 1     .38658734468607814 2018  3 2   2211
0     .6632438 0 22.496624   .024247756  .429839 .171623  .296507 0 48.1985  9  .3333333 1    -.09406542526262318 2015  3 4   2242
0     .7658159 0 23.312296    .02627352  .482263 .172226   .42112 0 29.5417 12  .3333333 0    -.09112069846520099 2017  3 4   2271
1     .7135918 1  23.70143   .021362694  .588407  .23567   .72431 0 29.6815 12  .3333333 0     .09541242903506242 2018  3 4   2271
0     .3925216 1 23.116613   .008775233  .513507 .186994  .968672 1 39.5067  9  .3333333 0    -.09745953982209754 2020 10 2   2285
1            1 0  23.61587  -.006748697  .734712  .06596  .894327 0 46.6676  9  .3333333 0     -.6186078538600104 2015  3 3   2309
1     .6098942 1  22.65274  -.005768759  .701191 .055315  .580472 0 24.6875  7  .4285714 0     .21706269725925886 2018  3 4   2313
1     .5116827 0  22.07821   .007702809  .376907 .039988  .487159 0  37.142  8      .375 1     -.5534196560013007 2015  3 3   2329
1     .9306198 1 21.223305  -.005161433  .191957 .018125  .552919 0 51.6813  7  .4285714 0     .12731100929346684 2018  3 2   2330
0            0 1  22.51812    .02537733  .471277 .114011  .332187 1 21.5549  9  .3333333 1      .3178894835848165 2020  3 2   2332
0    .17118557 0  22.45576   .009270319  .592059   .2165  .689021 0 48.2225  9  .3333333 1     .11836689496996455 2016  6 4   2336
0    .27657926 0 20.960585     .0166675  .189455  .22899  .440394 0 21.2228  9  .3333333 0     -.1317195583003028 2017  3 2   2360
0    .04205631 0 20.738434    .01462423  .145831  .07232   .18168 0 22.1239  9  .3333333 0     .49925092568614504 2017  3 3   2362
0      .749568 1 22.632803    .01335316  .224746 .139084 1.122952 0 36.8905  9  .3333333 0    .003174701123921153 2018 10 4   2377
1     .6310511 1 21.458397    .00811147  .181288 .156579  .714572 0 20.0958  9  .3333333 0     .15122049177817387 2018  3 1   2381
1           .5 1  23.18832    .00532092  .445859 .122432  .650856 0 21.0432 12  .3333333 0     .14242293219291557 2018  3 1   2390
1    .13146408 1 21.873865   .015368367  .248201 .038347  .671725 0 17.5816  9  .3333333 1                      0 2018 12 1   2398
0    .52650857 1  22.88623    .00290217  .544582 .056325  .672527 0 12.7912  9  .3333333 0     .18495277734569293 2019  3 3   2407
0            0 0 22.141815 -.0003614263  .204623  .06391  .374122 0 38.3181  7  .4285714 1     .10748921304322945 2017  3 3   2414
1       .97698 1  22.51107    .03252425  .343281 .091285  .578911 0 53.4631  9 .44444445 0     .20396482737072064 2018  3 4   2424
1     .3578187 1 21.499405    .02410278    .2391 .123387  .491256 0 30.4942  6        .5 1      1.114539876975416 2020  3 1   2432
0     .1985171 1  20.94404 -.0026766805  .448899 .057397  .345682 0 40.2277  7  .4285714 1    -.09155239173505625 2020  3 2   2451
1     .9350094 1   21.4925   .004653505  .427631 .054316  .539903 0  46.399  9  .3333333 0    -.17808484184770623 2018  1 1   2458
1    .58759856 0 22.239737   .011132246  .426752  .05014  .394206 1 32.9399  9  .3333333 0    -.30959203420320003 2016  3 1   2481
1      .849029 0   22.1377   .006715558   .36084  .04124  .377394 1  34.451  9  .3333333 0    -.13131395033913285 2017  3 1   2481
1     .8978257 0  21.98176   .018976565  .066125 .198252  .555553 0 26.8905  9  .3333333 0    -.08968978862344601 2017 17 2   2502
1     .5749914 1  23.39429  -.008274672  .701291 .020682  .566602 0 20.1242  7  .4285714 1     -.5107979040709122 2020  3 1   2506
0            0 0  22.14512   .007782157  .411673  .08289  .737374 0 19.3804 11  .3636364 0    -.23618537517202676 2016  3 1   2513
1     .5190855 0  22.62843   .007223045  .666378 .075301  .732954 0 51.7855  9  .3333333 1    -.08915782628295044 2016  3 1   2516
1     .6882586 1 22.190763   .001543706  .118335 .077017  .939936 0 45.6486  9  .3333333 0     .06951263157901355 2018  3 4   2516
0      .582819 0  21.32488    .01048358  .132721 .223256  .417493 0 18.6758  7  .4285714 0     -.2822090882974412 2016  3 3   2529
0      .991421 1  21.35625 -.0041242265   .25722 .026322  .757773 0 18.6758  6        .5 0    -.13923760373295324 2019  3 1   2529
0            0 1 24.510195    .02633591  .701285 .013977   1.2168 0   23.48  9  .3333333 1     .29988611896459805 2020  3 2   2532
0     .4285714 1  23.04207   .006420465   .58061 .097543  .875196 1 29.2779  9  .3333333 1     .07116975239085699 2020  5 3   2542
1      .342749 0 20.912077 -.0016797663  .331209 .067539  .432202 0 64.5093  8      .375 0                      0 2015 13 3   2549
1      .370618 0 20.848215   .007533599  .193778 .122771  .233189 0 64.5093  8      .375 0    -.16174510227651806 2017 13 2   2549
1     .7219743 0 21.382927   .025429364  .224064  .08548  .690184 0 42.2364  9  .3333333 1    -.33219447561476656 2017  3 2   2571
0     .3643026 1  20.62912  .0024850864  .045888 .101991  .400384 0 44.8521  6        .5 0      .2483188576050539 2018  3 3   2575
1            1 0 23.410753  .0011212789   .57184 .231417  .820575 0 15.6558  9  .3333333 1   -.012032504977274372 2016  3 1   2610
1     .7983786 1  21.48174 -.0041963775  .615567 .287986  .774453 0 51.5108  8      .375 0    -.08470062636245157 2020  3 2   2615
1     .9115749 0 21.960415   .002443449  .319653 .044632  .612902 0 26.7526  9  .3333333 1     -.1623094140805339 2017  3 2   2639
0     .7072687 0  21.59865   .020402573  .208345 .152655  .288401 0 22.2976  9  .3333333 1    -.33196838434399223 2015  6 2   2640
1            1 1   23.2325  -.017375221  .404433 .076527  .668864 0  18.187  9  .3333333 1   -.028948199517911277 2018  6 4   2640
0      .556566 1 20.848154 -.0041634594  .545086 .043104  .288331 0 15.2722  9  .3333333 0    -.32256944530064413 2020  3 1   2655
1     .8010126 1  21.93639  -.011914815  .285298 .084275  .716213 0 28.5634  7  .4285714 0     -.2908502017767989 2018  3 4   2656
1  .0009701049 1 22.930727 -.0022225392  .167395  .41351  .626943 0 20.0177  9  .3333333 0     .04160562054728323 2018  3 1   2665
1     .8957849 0 22.026474    .01939695  .426996 .054574  .821176 0 27.2823  9  .3333333 0     -.1473419285452654 2017  3 4   2671
1     .6494189 0  21.75721  .0045995745  .171421 .256501  .706801 0 28.0444  7  .4285714 0     -.2291572837987753 2017  3 2   2674
1     .6895479 0 21.837187   .032463256  .216014 .074483  .422054 0 44.9487  7  .4285714 0      .8364884687459839 2015  3 3   2681
1     .6310632 0  22.15345    .02070435  .299201 .073333  .404426 0  44.537  9  .3333333 1    .051787568568377296 2017  3 2   2681
1     .9585486 1  21.99116    .04749272  .450857   .0208  .288879 0 52.4058  8      .375 1   -.056044579584112464 2018  7 1   2711
0     .7650604 1 20.404306   .006018405  .322787 .044424  .462926 0 21.6254  7  .4285714 0     -.1312791376208874 2019  3 3   2715
1     .9027508 0  22.47264   .005777257  .660709 .013812  .821545 0 33.7341  8      .375 0                      0 2015  3 3   2716
0            0 1  20.71438   -.07405326  .412561 .051183  .488725 0 29.3194  7  .4285714 0    -.04733867345714238 2018  3 4   2723
0            0 0 22.061296  -.009817184  .315831 .127236  .530697 0 41.6164  9  .3333333 1   -.061597975845205766 2016  3 3   2737
1     .9481014 1  21.68237   .004915435  .396768 .136516  .848198 0 23.8905  8      .375 1   .0035598943172787667 2018  3 1   2740
1     .7999068 0 22.020777  -.013915107  .549905 .223632  .673259 0 45.3136  6  .3333333 1    -.27238514859880225 2017  3 4   2766
1      .318254 0  21.37551    .02417484   .51316 .048042  .564048 0    52.5  7  .4285714 1    .014436309071632625 2017  3 2   2768
1     .6650006 1  20.99927   .007399396  .495889 .100304  .748179 0 51.0156  7  .4285714 0    -.33615121245384216 2018  5 3   2856
1      .745595 1 21.156986  -.025304386   .58245 .085945  .790942 0 51.0156  7  .4285714 0    -.08170498822775163 2019  5 4   2856
0            0 1  20.06174   .017579691  .158399 .205815  .414944 0 62.7782  7  .4285714 0     .10074137946108208 2021  3 2   2888
0            0 1  21.74554   .023523184   .34932 .265262  .313821 0 28.9815  9  .3333333 1    -.29569917294234616 2020  3 3   2891
0     .1186291 0  22.32478   .002874133  .319676 .043669  .413086 0 19.3454 12  .3333333 0     -.2116825372417772 2016  9 1 300010
1     .2725401 1 22.341627    .01704489   .33201 .104638  .595541 0 20.9055  9 .44444445 1     .37885174631782204 2021  9 3 300031
1     .7401816 0  22.51858   .008415059  .579887  .05341  .541964 0 32.7698  7  .4285714 0     .14449894794704043 2017  3 2 300043
1     .7437187 0 20.865105  .0081653185  .415402 .157196  .245934 0 27.8554  7  .4285714 1    -.17818031869209772 2017  9 2 300052
1            1 1 21.691767   -.14534728  .629544 .063097   .81314 0  14.893  9  .3333333 1     .06593332979165667 2018  3 4 300056
0     .5003876 1 22.135046   .020528555  .182719 .113135  .829906 0 26.1496  9  .3333333 0     -.4001265834309844 2018  3 2 300061
1     .6036838 1 21.549654   .017761713  .238457 .291283  .386285 0 21.5828  5        .4 1     .04468417758148835 2018  3 1 300065
1     .6321993 1 21.497147   .010999167  .215061 .149415    .5741 0 19.6405  5        .4 1    -.12484560900074804 2018  3 4 300065
1     .6636558 1  21.46057  -.007652415  .298533 .127019  .494445 0 19.6405  5        .5 1    -.02117938495628635 2020  3 1 300065
1     .7558506 1  24.59995  .0034404655  .575319 .109056  .671653 0 22.8544  7  .4285714 0    .009760280229569318 2018 13 1 300070
0            0 1 22.198923  .0011995313  .122977 .374279  .600923 0 15.0047  6        .5 1    -.22826938183058232 2019  3 3 300079
1     .8215045 1  21.79581  -.006897378  .384651 .036622  .853649 0 17.8646  7  .4285714 1      .0963941975647351 2018  2 1 300084
1     .4577186 0  21.41663  .0044656834  .577435 .020557  .420296 0 18.1627  9  .3333333 1    .003703753803175447 2015  3 3 300091
0     .9999006 0 21.464367  .0021726605  .147185 .122813   .43592 0  16.974  7  .4285714 0      .6594421950675684 2015  3 1 300102
1     .8371637 1 22.302826    .02647491  .536661 .034719  .867827 0 23.9152  7  .4285714 1    -.34659107476329354 2018  3 4 300108
0            0 1  21.46671   .014307636  .266921 .190325  .316445 1      26  9  .3333333 0    -.03813938372966974 2019  3 1 300114
1     .7316653 0 21.953865   .003876171  .397461 .086579  .518696 0 21.3033  5        .4 1     -.2325990066834941 2017  3 2 300128
1     .5049037 1  23.07233   .012514503  .535729 .070698   .64343 1 26.6482  7  .4285714 0     .01668124858877751 2018  3 1 300145
0    .40322515 1 21.785473  -.003251654  .136258 .137927  .873306 0 12.7023  5        .4 0     .21332207056032915 2021  9 3 300148
0            0 0 20.450235   .022454957  .045888 .127387  .097598 0 24.0929  7  .4285714 0    .011023936087231512 2016  3 2 300149
1     .9409711 0  21.84431  -.006607469  .487311 .045883  .487593 0 29.5006  7  .4285714 1    -.26129752700733455 2017 13 3 300152
1            0 0  21.12339   .003530235  .227306 .222957  .484769 0 37.3834  7  .4285714 0    -.19616798837255855 2017  3 2 300155
1     .9990442 0 21.662207    .01981125  .337769 .228359  .464939 0 21.2091  9  .3333333 0    -.22905385862484795 2017  3 2 300173
1     .8238848 0 21.838757   .014923182  .545304  .13564   .29186 0 32.9028  9  .3333333 0     -.5780982598913436 2015 11 3 300178
1     .6841965 1  23.76799  -.003507872  .699027 .179648   .75003 0 41.7622  7  .4285714 0    -.00390466110249299 2018  5 1 300197
1     .9046198 1 22.493786   .017588392  .325769 .306619   .47358 0  25.365  7  .4285714 0     .02298700740813997 2018  3 1 300199
1            1 1 21.813334  .0045026415  .340014  .26494  .606351 0 14.4603 10        .5 0        .31728735149205 2018  3 1 300213
0     .9873234 1 21.931715 -.0030190675  .332804 .048892   .59194 0 20.9516  7  .4285714 0     -.2837515542488247 2018  3 2 300221
1     .6704647 1   22.5823   .015625594  .591352 .130462  .701814 0 41.4058  7  .4285714 1     .11049772965371907 2018  3 4 300232
1     .5314783 1  22.71992  .0008975485  .524161 .074754  .703096 0 33.6348  7  .4285714 1     -.3865788486199717 2020  3 2 300232
1     .8648745 1  22.82934    .01593557  .575679 .035719  .533969 0 26.2884  9  .3333333 0   -.036146927037850496 2018  5 1 300237
1     .3311583 0  20.38745   .036520425   .24516 .157818   .21899 0 33.5275  9  .3333333 1    -.11836174899914287 2017  3 2 300246
1     .7832754 0  21.78255   .005978856   .18192 .157715  .612162 0 14.4376  9  .3333333 1     -.0445251219166084 2017  3 2 300247
1     .9857481 1 22.913004  .0025120245  .610037 .045022  .925322 0 13.4828  9  .3333333 0    -.15554742990987314 2018  3 1 300256
1            0 0  20.78806   .007994743  .376146 .062202  .511801 0 28.1211  7  .4285714 1      -.144889711556364 2017  3 2 300260
1     .6979561 1 22.403843  -.006904245  .568191 .050863  .856025 0 41.6943  7  .4285714 0     .40191864392808285 2018 13 4 300262
1    .29424945 0  20.27915  -.011766585  .045888 .256514  .137059 0 29.1506  9  .3333333 0     .29186290833517226 2016  9 1 300264
1    .50768805 0  20.55292  -.010779643  .286226 .157874   .26405 0 29.5004  7  .4285714 0    .045233250846826945 2017  9 2 300264
1     .6517136 0  22.84213   -.02762276  .412065 .093067  .830384 0 18.8079 11  .3636364 1    -.27703503870648605 2017 11 4 300269
1     .9951339 1 21.047047   .001748974  .361347 .099754  .563743 0  24.576  8      .375 1    -.02932054444183463 2018  9 3 300290
1     .2742808 1  23.29528   .028339105  .418399 .088991  .638635 0  30.216  9  .3333333 1    -.43179903854898427 2018  3 3 300296
1     .2742808 1  23.40386    .02292815  .467457    .156  .657006 0  30.216  9  .3333333 1     .16957717610837264 2018  3 4 300296
0     .8224062 0   22.3596    .02023436  .217166 .073752  .559094 0  30.235  9  .3333333 1  -.0013534660620244665 2017  3 2 300307
0            0 1  22.08149    .00496813  .318569 .056766  .541643 0 17.3923  9  .3333333 1     -.1093182316636897 2021  3 3 300307
1     .4153179 0  21.89628  .0033895064  .476654 .077329   .30319 0 38.3661  5        .4 0      -.255952924489975 2017  3 2 300309
0     .4354178 1 21.721395  -.003855528  .616083 .029183   .51869 0  39.027  7  .4285714 0      .4120870654860993 2020  3 1 300318
1     .8924512 1 22.820147   -.03653899   .39112 .283863  .731476 0 33.5997  7  .4285714 0                      0 2018  9 4 300324
1     .9688827 0 21.478657   .009125053  .606908 .188047  .460242 0 32.8987  9  .3333333 0    -.23475888122716715 2015  3 3 300325
0     .2641767 1 21.579025     .0047857  .407881 .145935  .227106 0 14.9629  9  .3333333 0    -.14349445349603518 2021  9 3 300348
1            1 1  21.93525   .014699864  .324316 .089403  .687769 0 34.4973  5        .6 1     -.1868557834988831 2018  3 4 300353
1     .9975692 0  20.34344  .0033247126   .37082  .24787  .099766 0 31.9707  9  .3333333 1     -.4359298809136798 2015  9 3 300359
1     .7510205 1 22.181055  -.003590918  .635557 .060432  .726369 0 22.9484  9  .3333333 0     .19539588099963678 2018  3 1 300370
0            0 1  20.60864    .04686939  .127611 .031409  .416343 0 37.9331  9  .3333333 0     .07301149201185964 2020  3 3 300371
1     .9531569 1  22.46001    .01277796  .540681 .088004  .914441 0 36.8229  7  .4285714 1     -.3845862454277057 2018  3 3 300393
1     .7913252 1  21.18667    .04640011  .069492 .184622   .25459 0 36.0951  9  .3333333 0    -.41388743559777785 2018  3 3 300401
0            0 1  21.73963   .008965104  .489268 .160369  .828905 0 19.3068  9  .3333333 0     .06756034191210492 2021  3 2 300407
1     .7682842 1 21.791153   .010304288  .291099 .052184   .41771 0 46.2262  9  .3333333 1     .12759175506489862 2018  3 1 300410
1     .6578388 0  20.74238   .008915341  .496562 .077539  .525107 0 50.4043  7  .4285714 1    -.22146099550103127 2017  3 2 300464
1            1 0 20.347645    .02697752  .236375 .434268  .448916 0 38.9245  9  .3333333 1    -.06323998653113438 2017  3 4 300551
0            0 1   20.5574    .02880557  .363753 .063769  .298195 0    25.5  7  .4285714 0     -.0662189812134778 2020  3 3 300585
1    .02404657 1 23.310616    .05775971  .321367 .294283  .204139 0 26.6215  5        .4 1    -.16951143486656328 2021  3 3 300601
1     .6835521 1  20.65046   .012912906  .464432 .113268  .572575 0 40.9625  9  .3333333 1    -.17419392850285254 2018  3 2 300626
0            0 1  26.44896  -.004844799   .74872  .00603   .97678 1  36.915  7  .5714286 0    .016799179994585245 2019  7 4 600029
0            0 1 22.811207  -.006699676  .369692 .052668 1.020818 1  42.046  9  .3333333 0     .04394692484771667 2019  3 4 600075
1     .9517987 0 23.209024   .005478035  .733685 .005285  .573807 0  33.776  5        .4 1   -.002386545290047115 2017  3 2 600086
0            0 0  25.07936   .010072837  .664418 .153373  .981794 0 11.6366 12  .4166667 0   .0016009924931208452 2016  3 2 600089
0     .4844792 1 23.418304  .0026493766  .477798 .050355 1.009477 1 34.5699  9  .3333333 0    -.11710985373436167 2019  3 3 600231
0            0 0  19.63727    .09615283  1.05717  .01428  .087851 0 26.8973  9  .3333333 1     -.0954357578120929 2016  1 3 600265
0      .435078 1 23.407543   .007702664  .422376 .093299 1.243318 0 35.6431  9  .3333333 0    -.04277806623079439 2020  3 2 600308
0     .7013075 1  22.59021   .005534092  .367749 .056651  .715872 0 13.0008  7  .4285714 1    -.16896457691719335 2019  3 3 600330
0            0 1  22.47474 -.0045258417  .644442 .026745  .749334 1 58.7509 11  .3636364 0     .26913376718756354 2021  4 3 600333
0    .47607705 1  26.77559   .007183976  .872739 .105346  .920408 0  36.227  9  .3333333 0    -.43130380600340035 2019 10 1 600340
1     .8368456 0  23.73068   -.00488284  .695089 .062832  .785328 0 53.1409  7  .4285714 1     .06560832205811717 2017  3 2 600346
1      .782302 1  25.46907   .017336557  .749887 .091365  .925156 0 29.7181  7  .4285714 1   -.055913144969207185 2018  3 3 600346
1     .3892873 1  25.76777   .024940344  .807812 .064384  .808718 0 30.0509  7  .4285714 1    -.09854391964783138 2019  3 2 600346
1     .2352311 1  25.88449    .01922463  .789315 .061894  .778829 0 30.1139  7  .4285714 1    -.04976288367640347 2019  3 4 600346
1     .1566945 1  25.97569   .018644746  .753836  .06017  .659537 0 29.8421  7  .4285714 1      .3411362550023993 2020  3 4 600346
0      .661939 1  22.47275  .0017003987  .459604 .382775  .641488 0 23.3983  6        .5 0     .04517372069716297 2019  3 4 600360
0     .3623271 0 22.173643   .009962313  .456647 .091991  .475666 0  31.338  9  .3333333 0      .2567057033430653 2016  3 3 600439
0            0 1  20.79213  -.002649176  .427094 .322445  .494864 1 36.8164 11  .3636364 0      .2649242192403183 2021  3 3 600444
0    .26726076 1 22.014925  .0014494708  .591517 .123144  .684544 1  14.258  9  .3333333 0    -.01948412810179123 2019  3 3 600448
0            0 1  23.54738   .007701847  .606597 .086585  1.01381 1 33.5524  9  .3333333 0     -.1090634709159376 2021  3 3 600480
0            0 0  23.36157   .009406263  .360812 .047724 1.084768 1 62.4298  5        .4 0    .009020793247705772 2016  2 4 600508
0     .6114326 1 24.539583    .00894955  .620814 .050155 1.079603 0  28.243  7  .4285714 1    -.04868503948826297 2020  3 4 600567
1            1 0 22.611393    .00534941  .307209 .054053  .605177 0 27.1303  9  .3333333 1     -.2985858144546044 2016  3 1 600568
0            0 0  24.14273   .023531994  .482625 .282564  .557201 1 30.5753  9 .44444445 0     .05897044167939547 2015  3 2 600600
0            0 0  23.18254   .008274175  .498252 .203234  .673632 1 44.8454  7  .4285714 0     -.4034485555690125 2016 10 3 600604
0            0 0   20.2786   .007284536  .226606 .033067  .166098 0 24.3789  9  .3333333 1       .585684180265722 2015  3 1 600615
0            0 0  21.55271   .007720045  .279857 .135833  .316044 1  30.083  9  .3333333 0     .41188393277189883 2015  3 1 600630
0            0 1  23.83587   .008585018  .580881 .123725  .871618 0 18.0711  9  .3333333 0      .2803870438421696 2020  4 2 600635
0            0 1  23.73287   .011790133  .622617 .130968  .560358 1 29.9163 11  .3636364 0   -.023191744472545572 2020  3 2 600667
0            0 1 22.621674   -.02041158 1.018136 .024767  .749401 1 16.4238  8      .375 0      .4635983027393882 2019  9 1 600701
0       .88701 1 23.681334   .005780789  .525293  .02777  .916239 0 19.1051  7  .4285714 0     .09153954367115591 2019  2 3 600711
0            0 0 20.968317   .011037055  .140066 .165021  .220093 1 29.9859  7  .4285714 0    -.12045754020625976 2016  3 3 600722
0            0 0  24.92975   .027391795  .566216 .263927  .720514 1 60.0979  9  .3333333 0     -.1345313645026236 2015  3 2 600741
0            1 1  25.51827  .0010030632  .848233 .028064 1.085041 0 20.7636  7  .4285714 0    .022286376395145302 2019  6 2 600751
0     .3318672 0   22.7944   .017172266  .454676 .041649  .813461 1 35.7794  9  .3333333 0     .07463445530653812 2016 11 2 600790
1     .9045767 1  23.69174    .02650521  .658819 .054612   .97224 0 76.9525  8      .375 0      .1405902269896886 2018  6 4 600828
0            0 1  21.87699 -.0023763196  .253003  .10045  .582373 1 34.2332  7  .4285714 0    -.33242397148868064 2021  6 1 600861
0            0 0  19.28841   -.02068241  .824874 .023951   .06985 0 19.9855  9  .3333333 1    -.22755082227285428 2015  6 2 600892
0            0 1  23.14914    .01556417  .329963 .084171  .246278 0 65.7524  8      .375 0    -.15109723645802042 2020  3 3 601689
0    .29991814 0 21.009176  .0017302285  .163564 .198732  .454089 0 60.3196  9  .3333333 0    -.24495131486580268 2016  3 3 603015
0            0 1 20.622696    .02524882  .072634 .162452  .530629 0 21.0654  9  .3333333 0    -.12825270221775242 2020  3 3 603037
0            1 0 23.293783   .006654749  .156135 .081715    .6284 0 33.2547  9  .3333333 0   -.019349734755202963 2017  3 3 603077
0            0 1 21.931345    .06706159  .161692 .180742   .15303 0 28.7483  9  .3333333 0    -.21598763472825033 2021  3 1 603267
0            0 1 22.380907    .03972865  .433639 .304337  .711804 0 33.3624  6  .3333333 1    -.09777169402567254 2020  3 4 603279
0     .5320329 1  21.50497   .007694268  .707826 .099067  .488629 0  46.771  7  .4285714 0    -.04376393424485725 2020  9 2 603322
0            0 0 21.275326    .01904242  .147341 .238606  .353355 0 33.2426  9  .3333333 0    -.13376861614579028 2016  3 4 603566
0     .7840972 0 22.652765    .02484536  .320489   .2563  .745196 0 67.8317  5        .4 1   -.016652915393096768 2017  3 4 603567
0            0 1 22.145754   .012963322  .322122 .338618   .55658 1 45.9758  9  .3333333 0     .04042580684870356 2020 12 3 603698
1     .4880457 1 21.672144   .009996806  .370607 .261186  .707591 0 40.0614  9  .3333333 1      .1635618882072225 2018  6 4 603716
0            0 1 21.388275     .0124513   .25368 .150989  .768778 0 30.5642  7  .4285714 0     .05418102223056631 2021  3 2 603767
0            0 1  22.58826    .06417773  .139437 .064182  .433112 0 53.6302  7  .4285714 0     .28280006431430627 2018  3 4 603806
0            0 1  20.63663   .006384746  .287559 .093378  .648446 0 22.4375  9  .3333333 0     .02511165821906225 2019  3 2 603829
0            0 1 22.098873   .028187815  .277828 .470317   .75357 1 59.7851 10        .4 1    -.07678590846520705 2018  9 4 603888
0     .6850176 1  21.90451   .008435733  .257466  .15916  .884423 0 31.0935  9  .3333333 0     .22406118735230907 2020  3 2 603889
end
benjann commented 2 years ago

Hi, thanks for reporting this. Seems to be a bug. I have no idea why order() and indicate() get in conflict with each other once you specify unstack, but I will try to look into this. Might take a while. ben

dreistein543 commented 2 years ago

Hi, thanks for reporting this. Seems to be a bug. I have no idea why order() and indicate() get in conflict with each other once you specify unstack, but I will try to look into this. Might take a while. ben

it seems incomprehensible that this conflict between order() and indicate() with specification of unstack only when I try to output it with a result computed by reg. that is to say, if I store the results of ivprobit twice and output them together, this conflict won't happen. so I suggest that this problem may occur when someone trying to output multiequation result and single-equation result together

NilsEnevoldsen commented 2 years ago

Here's a simpler replication indicating that something is going wrong even without indicate(). Note the equation names in the third and fourth estout. Maybe the equation named / is tripping up estout somewhere.

*ssc install estout, replace
version 16.1

sysuse auto, clear

eststo m1: regress weight length
eststo m2: ivprobit foreign (weight = length)

* correct
estout m1 m2, order(weight)

* correct
estout m1 m2, unstack

* incorrect
estout m1 m2, unstack order(weight)

* also incorrect
estout m2 m1, unstack order(weight)

Relevant output:

. * correct
. estout m1 m2, order(weight)

--------------------------------------
                       m1           m2
                        b            b
--------------------------------------
main                                  
weight                       -.0015013
length           33.01988             
_cons           -3186.047     3.643953
--------------------------------------
weight                                
length                        33.01988
_cons                        -3186.047
--------------------------------------
/                                     
athrho2_1                    -.0124362
lnsigma2                      5.522311
--------------------------------------

. 
. * correct
. estout m1 m2, unstack

----------------------------------------------------------------
                       m1           m2                          
                        _      foreign       weight            /
                        b            b            b            b
----------------------------------------------------------------
length           33.01988                  33.01988             
weight                       -.0015013                          
athrho2_1                                              -.0124362
lnsigma2                                                5.522311
_cons           -3186.047     3.643953    -3186.047             
----------------------------------------------------------------

. 
. * incorrect
. estout m1 m2, unstack order(weight)

----------------------------------------------------------------
                       m1           m2                          
                        _      foreign      foreign       weight
                        b            b            b            b
----------------------------------------------------------------
weight                       -.0015013    -.0015013             
length           33.01988                               33.01988
athrho2_1                                                       
lnsigma2                                                        
_cons           -3186.047     3.643953     3.643953    -3186.047
----------------------------------------------------------------

. 
. * incorrect
. estout m2 m1, unstack order(weight)

----------------------------------------------------------------
                       m2                                     m1
                  foreign       weight            /            _
                        b            b            b            b
----------------------------------------------------------------
weight          -.0015013                                       
length                        33.01988                          
athrho2_1                                 -.0124362             
lnsigma2                                   5.522311             
_cons            3.643953    -3186.047                          
----------------------------------------------------------------
benjann commented 2 years ago

This may well be as estout has been written long before things such as equation names equal to "/" appeared in Stata :)

A (somewhat tedious) workaround is to rename the equations:

. estout m1 m2, unstack order(weight) equations(eq1 = 1:1, eq2 = .:2, eq3 = .:3)

----------------------------------------------------------------
                       m1           m2                          
                      eq1          eq1          eq2          eq3
                        b            b            b            b
----------------------------------------------------------------
weight                       -.0015013                          
length           33.01988                  33.01988             
athrho2_1                                              -.0124362
lnsigma2                                                5.522311
_cons           -3186.047     3.643953    -3186.047             
----------------------------------------------------------------

Note that the new equation names must be different from the names already existing in the models (e.g. you could not use weight for the second equation).

benjann commented 2 years ago

ok, the trouble is not "/", the trouble is the empty equation name in m1. This makes order() fail. So it seems to me that this is a problem that has been always there and I am surprised that it has not come up earlier. Once you make sure that the equation has a name, everything works fine.

. estout m1 m2, unstack order(weight) equations(1)

----------------------------------------------------------------
                       m1           m2                          
                       #1           #1       weight            /
                        b            b            b            b
----------------------------------------------------------------
weight                       -.0015013                          
length           33.01988                  33.01988             
athrho2_1                                              -.0124362
lnsigma2                                                5.522311
_cons           -3186.047     3.643953    -3186.047             
----------------------------------------------------------------

or, for example,

. estout m1 m2, unstack order(weight) equations(main = 1)

----------------------------------------------------------------
                       m1           m2                          
                     main         main       weight            /
                        b            b            b            b
----------------------------------------------------------------
weight                       -.0015013                          
length           33.01988                  33.01988             
athrho2_1                                              -.0124362
lnsigma2                                                5.522311
_cons           -3186.047     3.643953    -3186.047             
----------------------------------------------------------------

Reason why the problem only occurs when specifying unstack: If unstack is not specified, the default behavior is to match (the first equation of) m1 automatically with the first equation of m2 and name it main. If unstack is specified, matching equations is skipped so that the equation in m1 remains unnamed.

benjann commented 2 years ago

I now posted a fix. The subroutine implementing order() now temporarily replaces empty equation names with a tempname so that order() will not make a mess. Results are now correct for Niels' first "incorrect" example:

. estout m1 m2, unstack order(weight)

----------------------------------------------------------------
                       m1           m2                          
                        _      foreign       weight            /
                        b            b            b            b
----------------------------------------------------------------
weight                       -.0015013                          
length           33.01988                  33.01988             
athrho2_1                                              -.0124362
lnsigma2                                                5.522311
_cons           -3186.047     3.643953    -3186.047             
----------------------------------------------------------------

The second "incorrect" example by Niels will still be incorrect, but this has nothing to do with order(). Results will also be incorrect without order():

. estout m2 m1, unstack 

----------------------------------------------------------------
                       m2                                     m1
                  foreign       weight            /            _
                        b            b            b            b
----------------------------------------------------------------
weight          -.0015013                                       
length                        33.01988                          
athrho2_1                                 -.0124362             
lnsigma2                                   5.522311             
_cons            3.643953    -3186.047                          
----------------------------------------------------------------

That is, also unstack seems to have problems with unnamed equations in some situations. I did not look into this yet.

NilsEnevoldsen commented 2 years ago

The second "incorrect" example by Niels will still be incorrect, but this has nothing to do with order().

Interesting. Sorry for not noticing this.

benjann commented 2 years ago

Don't be sorry. You helped identifying a bug.

benjann commented 2 years ago

I now posted an update that also fixes the second issue reported by Nils.

. estout m2 m1, unstack order(weight)

----------------------------------------------------------------
                       m2                                     m1
                  foreign       weight            /            _
                        b            b            b            b
----------------------------------------------------------------
weight          -.0015013                                       
length                        33.01988                  33.01988
athrho2_1                                 -.0124362             
lnsigma2                                   5.522311             
_cons            3.643953    -3186.047                 -3186.047
----------------------------------------------------------------

Both issues were related to the fact that rownumb() interprets "_:" as "any equation". I now added a routine to estout that mimics the functionality of rownumb() but treats "_:" as distinct equation name. This routine is now also used to handle the first issue above. (Potentially, there are further instances of rownumb() in the code of estout that should be replaced by the new routine, but I am hesitant to do this without need because there is some cost in terms of speed.)

Note that the update does not fix all issues related to unstack; there are other ways how you can break it. My impression, however, is that these are very unlikely cases so I did not start trying to fix them.

benjann commented 2 years ago

Potentially, there are further instances of rownumb() in the code of estout that should be replaced by the new routine, but I am hesitant to do this without need because there is some cost in terms of speed.

... and also because I am unsure whether in some of these instances the default rownumb() behavior is actually more appropriate.

benjann commented 2 years ago

I now posted another update that undoes the previous fix and implements a more general approach to solve the problem. This also fixes a number of other issues. As noted above, the trouble is that Stata's rownumb() interprets equation specification "_" as any equation, but at the same time "_" is technically used by Stata as the name of an unnamed equation. In cases where the collected table of results contained both unnamed and named equations this could lead to various issues (such as the ones above; although many of them were not very likely to occur). I now changed estout so that it renames unnamed equations internally to "__"; this solves these problems because "__" is interpreted as a specific equation by rownumb() and not as any equation. The renaming is only done internally and is undone at the end. A plus of the new approach is that users can now specify "_:coef" in options such as drop(), keep() etc. to address coef only in the unnamed equation; before this was not possible as"_:coef" addressed coef in any equation. A minor disadvantage of the new approach is that if a model actually names an equation as "__" then estout will treat this as an unnamed equation; to my knowledge, no official Stata commands use "__" as equation name.

I tried to carefully check all options and functionalities for which the change of "_" to "__" matters, to make sure that I did not break anything and everything works fine. Naturally, there is no guarantee that the change did not introduce any new issues.

NilsEnevoldsen commented 2 years ago

@benjann This is (re-)fixed in 3.30, which is available on SSC. It would be appropriate to close this issue.