Announcement

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

  • Exporting really simple statistics (ci and proportions) of a dummy, by categorical variable

    Dear Statalists,

    I'm trying to export a table of information from Stata but I cannot find a solution. I have a variable list of 20 variables, all of them are dummies. For example: education is equal to 1 if the respondent mentions education and 0 otherwise. I have 19 other similar variables.
    I want to see the propensity for respondents preferring Parties A, B, C, D or E (categorical) to mention variable 1(..., N) on my variable list.

    I can easily do this in stata:
    Code:
    by party: ci prop $dictionary
    But I can not find out how to export this.
    I have tried asdoc (which I think isn't working because I have too many variables in my $dictionary), esttout, outreg2 and dtable. None of it seems to be capable of giving me the output that I want. Do any of you have an idea for a solution?

  • #2
    How about this?
    http://repec.org/bocode/e/estout/estpost.html

    Comment


    • #3
      Originally posted by Henry Strawforrd View Post
      Code:
       by party: eststo: ci prop $dictionary2
      Thanks. At first glance this would seem to work - as it does still do the 'by party: ci prop $dictionary2", but I can't specify adding percentages (prop) to the output. Only CI.
      Also whatever it is that Stata stores in est* definitely isn't what went into the eststo command.

      Comment


      • #4

        Here is an example of how this might be done with collect. The
        dummy variables in this example have missing values, so if that is true
        in your data, you might want to add the sample sizes to the table, but I
        will leave that up to you.

        Code:
        webuse nhanes2l, clear
        sort region
        
        collect style use dtable, replace
        
        global vlist heartatk diabetes highlead highbp
        foreach var of global vlist {
            collect, tags(var[`var']) : by region : ci prop `var'
        }
        
        * show list of collected results
        collect levelsof result
        
        * build and style composite result for the CIs
        collect composite define ci = lb ub, notrim
        collect style cell result[ci], sformat("[%s]")
        collect style cell result[proportion ci], nformat("%5.3f")
        
        * result auto levels for the layout
        collect style autolevels result proportion ci
        
        * use shorter labels
        collect label levels result proportion "Prop" ci "%95 CI", modify
        
        collect style column, dups(center)
        
        collect layout (var) (region#result)
        Here is the resulting table.
        Code:
        . collect layout (var) (region#result)
        
        Collection: default
              Rows: var
           Columns: region#result
           Table 1: 4 x 8
        
        ---------------------------------------------------------------------------------------------------
                                     NE                  MW                  S                   W
                             Prop    [%95 CI]    Prop    [%95 CI]    Prop    [%95 CI]    Prop    [%95 CI]
        ---------------------------------------------------------------------------------------------------
        Prior heart attack  0.037 [0.029 0.046] 0.044 [0.036 0.052] 0.046 [0.039 0.054] 0.056 [0.047 0.065]
        Diabetes status     0.047 [0.038 0.057] 0.045 [0.038 0.053] 0.056 [0.048 0.066] 0.044 [0.036 0.052]
        High lead level     0.067 [0.052 0.084] 0.071 [0.057 0.086] 0.045 [0.035 0.058] 0.056 [0.044 0.070]
        High blood pressure 0.441 [0.419 0.462] 0.400 [0.382 0.419] 0.427 [0.408 0.445] 0.428 [0.409 0.447]
        ---------------------------------------------------------------------------------------------------

        Comment


        • #5
          Originally posted by Jeff Pitblado (StataCorp) View Post
          Here is an example of how this might be done with collect. The
          dummy variables in this example have missing values, so if that is true
          in your data, you might want to add the sample sizes to the table, but I
          will leave that up to you.

          Code:
          webuse nhanes2l, clear
          sort region
          
          collect style use dtable, replace
          
          global vlist heartatk diabetes highlead highbp
          foreach var of global vlist {
          collect, tags(var[`var']) : by region : ci prop `var'
          }
          
          * show list of collected results
          collect levelsof result
          
          * build and style composite result for the CIs
          collect composite define ci = lb ub, notrim
          collect style cell result[ci], sformat("[%s]")
          collect style cell result[proportion ci], nformat("%5.3f")
          
          * result auto levels for the layout
          collect style autolevels result proportion ci
          
          * use shorter labels
          collect label levels result proportion "Prop" ci "%95 CI", modify
          
          collect style column, dups(center)
          
          collect layout (var) (region#result)
          Here is the resulting table.
          Code:
          . collect layout (var) (region#result)
          
          Collection: default
          Rows: var
          Columns: region#result
          Table 1: 4 x 8
          
          ---------------------------------------------------------------------------------------------------
          NE MW S W
          Prop [%95 CI] Prop [%95 CI] Prop [%95 CI] Prop [%95 CI]
          ---------------------------------------------------------------------------------------------------
          Prior heart attack 0.037 [0.029 0.046] 0.044 [0.036 0.052] 0.046 [0.039 0.054] 0.056 [0.047 0.065]
          Diabetes status 0.047 [0.038 0.057] 0.045 [0.038 0.053] 0.056 [0.048 0.066] 0.044 [0.036 0.052]
          High lead level 0.067 [0.052 0.084] 0.071 [0.057 0.086] 0.045 [0.035 0.058] 0.056 [0.044 0.070]
          High blood pressure 0.441 [0.419 0.462] 0.400 [0.382 0.419] 0.427 [0.408 0.445] 0.428 [0.409 0.447]
          ---------------------------------------------------------------------------------------------------
          Thanks Jeff. Your code works perfectly, but I wanted to have this kind of table in my paper. How do I export this kind of table?

          Comment


          • #6
            Code:
            help collect export

            Comment


            • #7
              Yep sorry should have done that.
              Here's the code for future readers:
              collect export party.docx, as(docx)

              Comment

              Working...
              X