Announcement

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

  • Confidence intervals in one cell for esttab

    I'd like to obtain confidence intervals on 1 row using esttab but seems like my code only captures ub on a separate column. Is there a way to capture them in the same column and as a parentheses () or bracket []

    * Get the unique levels of stoptype and store them in a local macro
    levelsof type, local(levels)

    * Loop through each level of stoptype with a new name for the loop variable
    foreach i of local levels {

    * Use estpost to perform a confidence interval calculation for each stop_level and store the results
    eststo: estpost ci monitorstopok monf mons if type == "`i'"
    }
    eststo: estpost ci monitorstopok monf mons

    * Use esttab to export the results, with b, lb, and ub in one row
    esttab using type_upper_lower.rtf, cell(b(fmt(%5.3f)) "lb(fmt(%5.2f)) ub(fmt(%5.2f))") unstack varwidth(15) replace

  • #2
    See #4: https://www.statalist.org/forums/for...ence-intervals. Note that estout is from SSC, as you are asked to explain (FAQ Advice #12).

    Comment


    • #3
      Okay -- thanks that was helpful. I'm struggling though to get the bracket after ub. Here is the code that only puts a bracket before lb but I cannot get it for ub. Something I'm overlooking clearly!
      esttab using type_ci.rtf, label cells(b(fmt(2)) lb(par("[") fmt(a2))&ub(fmt(a2))) ///
      incelldelimiter("-") unstack varwidth(15) replace

      Comment


      • #4
        From the linked thread, notice that I create a redundant matrix and estadd it for just that reason. My matrices below are named "cll" and "clu", corresponding to the lower CI and upper CI, respectively.

        Code:
        sysuse auto, clear
        estimates clear
        regress mpg weight, nocons
        estadd mat cll= r(table)["ll", 1]
        estadd mat clu= r(table)["ul", 1]
        mat blank= J(`=rowsof(e(b))', `=colsof(e(b))', 1)
        mat colnames blank= `:colnames e(b)'
        estadd mat blank
        esttab .,  label cells(b(fmt(2)) cll(par("[") fmt(a2))&clu(fmt(a2))&blank(fmt(a0) par("]"))) ///
        incelldelimiter("-") unstack varwidth(15) replace substitute(-]1 "]" ) collab(none)
        Res.:


        Code:
        . esttab .,  label cells(b(fmt(2)) cll(par("[") fmt(a2))&clu(fmt(a2))&blank(fmt(a0) par("]"))) ///
        > incelldelimiter("-") unstack varwidth(15) replace substitute(-]1 "]" ) collab(none)
        
        ----------------------------
                                 (1)
                        Mileage (m~)
        ----------------------------
        Weight (lbs.)           0.01
                        [0.0055-0.0070]
        ----------------------------
        Observations              74
        ----------------------------

        Comment


        • #5
          Also note that it is not a good idea to use a dash as a separator as the upper CI can be negative. Use a comma instead.

          Comment

          Working...
          X