Announcement

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

  • new issues with esttab

    Hi,

    I wrote a program to export the results of my survey weighted cross tabulations into an excel file using esttab, matselrc, and putexcel (Stata 15.1). I used this program numerous times without problems, but now I get no results after the esttab command. It appears the esttab command is not storing the estimates in memory. Has there been a change in the esttab command? How can I work around this issue?


    Code:
    
    global brfss obese
    
    foreach var in $brfss {
    
    capture noisily svy, subpop(if year==2010): tab mracealpha `var', row ci percent obs format (%7.1f)
    esttab ., cells("obs b(fmt(1)) lb(fmt(1)) ub(fmt(1)) se(fmt(1))")unstack noobs
    
    matlist r(coefs)
    matrix results=r(coefs)
    matlist results
    *return list
    matselrc results r1 , r(10/17) c(1/5)
    matlist r1
    
    putexcel set draftresults.xlsx, sheet(ModelSum`var'1) modify
    putexcel set draftresults.xlsx, sheet(ModelSumsmoker1) modify
    putexcel B2=matrix(r1)
    
    }

    I get this Stata ouput:

    HTML Code:
    (running tabulate on estimation sample)
    
    Number of strata   =        18                  Number of obs     =     18,559
    Number of PSUs     =    18,559                  Population size   =  8,238,102
                                                    Subpop. no. obs   =     18,559
                                                    Subpop. size      =  8,238,102
                                                    Design df         =     18,541
    
    -------------------------------------------------
    mracealph |            obese, BMI>=30            
    a         |          No          Yes        Total
    ----------+--------------------------------------
         AIAN |        53.5         46.5        100.0
              | [42.3,64.3]  [35.7,57.7]             
              |        85.0         61.0        146.0
              | 
        Asian |        92.3          7.7        100.0
              | [90.3,93.9]    [6.1,9.7]             
              |      1195.0         94.0       1289.0
              | 
        Black |        66.1         33.9        100.0
              | [61.1,70.8]  [29.2,38.9]             
              |       429.0        212.0        641.0
              | 
     Multiple |        76.3         23.7        100.0
              | [70.9,80.9]  [19.1,29.1]             
              |       294.0        111.0        405.0
              | 
         NHPI |        70.9         29.1        100.0
              | [58.5,80.8]  [19.2,41.5]             
              |        64.0         33.0         97.0
              | 
        White |        76.7         23.3        100.0
              | [75.7,77.7]  [22.3,24.3]             
              |     12401.0       3580.0      15981.0
              | 
        Total |        78.2         21.8        100.0
              | [77.3,79.1]  [20.9,22.7]             
              |     14468.0       4091.0      18559.0
    -------------------------------------------------
      Key:  row percentage
            [95% confidence interval for row percentage]
            number of observations
    
      Pearson:
        Uncorrected   chi2(5)         =  528.8654
        Design-based  F(4.92, 91168.18)=   37.7259    P = 0.0000
    
    Note: 23 strata omitted because they contain no subpopulation members.
    
    ------------
                
                
                
    ------------
    ------------
    
    . 
    end of do-file
    
    
    . matlist r(coefs)
    
                 | active                                                
                 |       obs          b         lb         ub         se 
    -------------+-------------------------------------------------------
             p11 |        .y     .53501         .y         .y   .0571526 
             p12 |        .y     .46499         .y         .y   .0571526 
             p21 |        .y   .9228453         .y         .y    .009021 
             p22 |        .y   .0771547         .y         .y    .009021 
             p31 |        .y   .6612203         .y         .y     .02494 
             p32 |        .y   .3387797         .y         .y     .02494 
             p41 |        .y   .7629963         .y         .y   .0255429 
             p42 |        .y   .2370037         .y         .y   .0255429 
             p51 |        .y   .7087532         .y         .y   .0576917 
             p52 |        .y   .2912468         .y         .y   .0576917 
             p61 |        .y   .7671453         .y         .y   .0051494 
             p62 |        .y   .2328547         .y         .y   .0051494 

  • #2
    Hi all,

    I found my error. I somehow dropped the estpost command in my first line. The below code now works:

    Thanks

    Code:
    global hys ecig_vape alc30day
    
    foreach var in $hys {
    
        
     capture noisily estpost  svy, subpop(if year>2014): tab raceeth `var', row ci percent obs format (%5.4fc) 
        esttab ., cells("obs b(fmt(1)) lb(fmt(1)) ub(fmt(1)) se(fmt(1))")unstack noobs
        matlist r(coefs)
        matrix results=r(coefs)
        matlist results
        *return list
        *matselrc results r1 , r(10/17) c(1/5)
        *matlist r1
        }

    Comment


    • #3
      Hi Susan,

      I'm looking to export a weighted cross tabulation from stata to excel, and am trying to use your code. However, what I am trying to do is much simpler, and I am unable to adapt your code to my purposes. It would be great if you could help me with this.

      This is my stata code:
      Code:
      svyset cluster [pweight = perwt], strata(strata)
      tab naics2017 skill [iweight = perwt], row
      And this is my stata output, which I would like to export to excel:
      Code:
                            | Skill categories (Fleckenstein et al 2011,
                            |                   p.1628)
                  naics2017 |       n/a  low-gener  high-gene   specific |     Total
      ----------------------+--------------------------------------------+----------
                 Unemployed |   1863042          0          0          0 |   1863042 
                            |    100.00       0.00       0.00       0.00 |    100.00 
      ----------------------+--------------------------------------------+----------
        Outside Labor Force | 132248332          0          0          0 | 132248332 
                            |    100.00       0.00       0.00       0.00 |    100.00 
      ----------------------+--------------------------------------------+----------
      Agriculture, Forestry |    199944     196790     922683    1317452 |   2636869 
                            |      7.58       7.46      34.99      49.96 |    100.00 
      ----------------------+--------------------------------------------+----------
      Mining, Quarrying, an |        94      68227     452293     409313 |    929927 
                            |      0.01       7.34      48.64      44.02 |    100.00 
      ----------------------+--------------------------------------------+----------
                 Utilities  |      1385     258077     840629     365116 |   1465207 
                            |      0.09      17.61      57.37      24.92 |    100.00 
      ----------------------+--------------------------------------------+----------
              Construction  |      4628    2807564    3410727    5822133 |  12045052 
                            |      0.04      23.31      28.32      48.34 |    100.00 
      ----------------------+--------------------------------------------+----------
              Manufacturing |      7194    2454982    7705827    8358803 |  18526806 
                            |      0.04      13.25      41.59      45.12 |    100.00 
      ----------------------+--------------------------------------------+----------
           Wholesale Trade  |      1633    1046252    2797857     885295 |   4731037 
                            |      0.03      22.11      59.14      18.71 |    100.00 
      ----------------------+--------------------------------------------+----------
              Retail Trade  |      2569   16907834    3451282    1928593 |  22290278 
                            |      0.01      75.85      15.48       8.65 |    100.00 
      ----------------------+--------------------------------------------+----------
      Transportation and Wa |      2096    2790155    1521786    3782979 |   8097016 
                            |      0.03      34.46      18.79      46.72 |    100.00 
      ----------------------+--------------------------------------------+----------
               Information  |       300     746352    2636463     406738 |   3789853 
                            |      0.01      19.69      69.57      10.73 |    100.00 
      ----------------------+--------------------------------------------+----------
      Finance and Insurance |         0    1901401    6101235      41115 |   8043751 
                            |      0.00      23.64      75.85       0.51 |    100.00 
      ----------------------+--------------------------------------------+----------
      Real Estate and Renta |      2299     822441    2573051     272503 |   3670294 
                            |      0.06      22.41      70.10       7.42 |    100.00 
      ----------------------+--------------------------------------------+----------
      Professional, Scienti |      2045    1040144   11183257     296107 |  12521553 
                            |      0.02       8.31      89.31       2.36 |    100.00 
      ----------------------+--------------------------------------------+----------
      Management of Compani |       123      27786     161661       5979 |    195549 
                            |      0.06      14.21      82.67       3.06 |    100.00 
      ----------------------+--------------------------------------------+----------
      Administrative and Su |    170487    4751960    2719510     926562 |   8568519 
                            |      1.99      55.46      31.74      10.81 |    100.00 
      ----------------------+--------------------------------------------+----------
      Educational Services  |      3297    3651622   13053558     542366 |  17250843 
                            |      0.02      21.17      75.67       3.14 |    100.00 
      ----------------------+--------------------------------------------+----------
      Health Care and Socia |      2147    8554652   16190130     408883 |  25155812 
                            |      0.01      34.01      64.36       1.63 |    100.00 
      ----------------------+--------------------------------------------+----------
      Arts, Entertainment,  |     18950    1933996    2313321     406636 |   4672903 
                            |      0.41      41.39      49.51       8.70 |    100.00 
      ----------------------+--------------------------------------------+----------
      Accommodation and Foo |      1020   11682777    3161060     552139 |  15396996 
                            |      0.01      75.88      20.53       3.59 |    100.00 
      ----------------------+--------------------------------------------+----------
      Other Services (excep |      4977    4454161    3106563    1803892 |   9369593 
                            |      0.05      47.54      33.16      19.25 |    100.00 
      ----------------------+--------------------------------------------+----------
      Public Administration |    610192    1991894    6527783     528414 |   9658283 
                            |      6.32      20.62      67.59       5.47 |    100.00 
      ----------------------+--------------------------------------------+----------
                      Total | 135146754   68089067   90830676   29061018 | 323127515 
                            |     41.82      21.07      28.11       8.99 |    100.00
      I would appreciate your advice on this roadblock.

      Best,
      Rosa

      Comment

      Working...
      X