Announcement

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

  • Setting up matrix

    Hello! I have the following code, which I'd like to put out into Excel instead of laboriously typing- any advice? All binary variables

    *Overlap between WHZ and MUAC
    *<125 mm & WHZ <-2
    svy: tabulate GAM GAMMUAC, ci obs deff
    *<135 mm & WHZ <-2
    svy: tabulate GAM MUAC135, ci obs deff
    *<130 mm & WHZ <-2
    svy: tab GAM MUAC130, ci obs deff
    *<120 mm & WHZ<-2
    svy: tab GAM MUAC120, ci obs deff
    *<115 mm & WHZ<-2
    Click image for larger version

Name:	Picture1.png
Views:	1
Size:	14.5 KB
ID:	1584401

    svy: tab GAM MUAC115, ci obs deff



  • #2
    Realizing now that I could use the source function!

    *Overlap between WHZ and MUAC
    syvset CLUSTER

    *<125 mm & WHZ <-2
    svy: tabulate GAM GAMMUAC, ci obs deff
    *<135 mm & WHZ <-2
    svy: tabulate GAM MUAC135, ci obs deff
    *<130 mm & WHZ <-2
    svy: tab GAM MUAC130, ci obs deff
    *<120 mm & WHZ<-2
    svy: tab GAM MUAC120, ci obs deff


    Advice on how to put this into a matrix, and then to Excel? I need to retain the confidence interval.

    Comment


    • #3
      The means and CIs are easy to export via esttab (SSC), but you will need some work to exactly replicate the table. Here is a reproducible example including 3 variables.

      Code:
      ssc install estout, replace
      webuse nhanes2b, clear
      eststo clear
      foreach var in diabetes heartatk fhtatk{
          estpost svy: tabulate race `var', ci deff obs
          eststo
      }
      esttab est* using myfile.xls, ci unstack collabels("") nonumber noobs replace
      Res.: (Note: Output for 2 variables shown to enhance readability)

      Code:
      . esttab est1 est2, ci unstack collabels("") nonumber noobs compress
      
      ----------------------------------------------------------------------------------------------------------------------------------
                             Mean                                                        Mean                                          
                                0                   1               Total                   0                   1               Total  
                                                                                                                                        
      ----------------------------------------------------------------------------------------------------------------------------------
      White                 0.851***           0.0281***            0.879***            0.852***           0.0270***            0.879***
                    [0.819,0.883]     [0.0241,0.0320]       [0.845,0.913]       [0.819,0.885]     [0.0236,0.0305]       [0.845,0.913]  
      
      Black                0.0899***          0.00564***           0.0955***           0.0932***          0.00237***           0.0955***
                   [0.0651,0.115]    [0.00392,0.00736]      [0.0695,0.122]      [0.0678,0.118]    [0.00124,0.00349]      [0.0695,0.122]  
      
      Other                0.0248*           0.000515              0.0253*             0.0250*           0.000353              0.0253*  
                 [0.00408,0.0456]    [-0.000274,0.00130]    [0.00384,0.0469]    [0.00414,0.0458]    [-0.000305,0.00101]    [0.00384,0.0469]  
      
      Total                 0.966***           0.0342***                1               0.970***           0.0297***                1  
                    [0.962,0.969]     [0.0305,0.0379]               [.,.]       [0.966,0.974]     [0.0260,0.0335]               [.,.]  
      ----------------------------------------------------------------------------------------------------------------------------------
      95% confidence intervals in brackets
      * p<0.05, ** p<0.01, *** p<0.001
      Last edited by Andrew Musau; 02 Dec 2020, 21:32.

      Comment


      • #4
        Thank you so much. What would be the next step for exporting this to Excel?

        Comment


        • #5
          The command already does this.

          Code:
          esttab est* using myfile.xls, ci unstack collabels("") nonumber noobs replace
          or you could use the file extension


          Code:
          esttab est* using myfile.csv, ci unstack collabels("") nonumber noobs replace
          and open the csv file in Excel. You get a clickable link to the file, or type

          Code:
          cd
          and within this folder lies your file.

          Comment


          • #6
            Thanks!!!

            Comment

            Working...
            X