Announcement

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

  • A seemingly bug with refcat (an option of estout), when using with tabstat ?

    Dear Statalist,

    I am using esttab and tabstat to produce descriptive statistics of 4 variables. I intend to add a row indicating the name of by-category, since I want to append different categories in the same table. I use refcat to tell esttab where to add a row, but it does not seem to work as I expected.

    Code:
    sysuse auto,clear
    
    recode length (100/150=1 "Less than 150")(151/200=2 "150-200")(200/250=3 "more than 200"), ///
    generate(length_cat) 
    
    eststo clear
    eststo: estpost tabstat  price weight mpg,by(length_cat)
    esttab ,cells("price weight mpg") refcat(1.length "Length category",nolabel)
    The output is
    Code:
    . esttab ,cells("price weight mpg") refcat(1.length "Length category",nolabel)
    
    ---------------------------------------------------
                          (1)                          
                                                       
                        price       weight          mpg
    ---------------------------------------------------
    Less tha~150         4261     1796.667     27.33333
    150-200          5327.958     2677.708      23.3125
    more tha~200     8161.043     3892.174     16.30435
    Total            6165.257     3019.459      21.2973
    ---------------------------------------------------
    N                      74                          
    ---------------------------------------------------
    Clearly, It can not recognize "1.length" and didn't add the row I I want. However if I change the label of 1.length to a single word "Less_than_150" (If space is included, it will not work again), and use the label inside refcat, it does work. The problem is, I cannot label all my category variables with a single word.

    Code:
    recode length (100/150=1 "Less_than_150")(151/200=2 "150-200")(200/250=3 "more than 200"), ///
    generate(length_cat2) 
    
    eststo clear
    eststo: estpost tabstat  price weight mpg,by(length_cat2)
    esttab ,cells("price weight mpg") refcat("Less_than_150" "Length category",nolabel)
    And the output is
    Code:
    . esttab ,cells("price weight mpg") refcat("Less_than_150" "Length category",nolabel)
    
    ---------------------------------------------------
                          (1)                          
                                                       
                        price       weight          mpg
    ---------------------------------------------------
    Length cat~y                                       
    Less_tha~150         4261     1796.667     27.33333
    150-200          5327.958     2677.708      23.3125
    more tha~200     8161.043     3892.174     16.30435
    Total            6165.257     3019.459      21.2973
    ---------------------------------------------------
    N                      74                          
    ---------------------------------------------------
    Is it a bug with tabstat or refcat? What should I do with my long value labels?

  • #2
    Does this approach help?
    Code:
    . esttab , cells("price weight mpg") posthead("Length category") 
    
    ---------------------------------------------------
                          (1)                          
                                                       
                        price       weight          mpg
    Length category
    Less tha~150         4261     1796.667     27.33333
    150-200          5327.958     2677.708      23.3125
    more tha~200     8161.043     3892.174     16.30435
    Total            6165.257     3019.459      21.2973
    ---------------------------------------------------
    N                      74                          
    ---------------------------------------------------

    Comment


    • #3
      Thanks a lot. it does help!

      Comment

      Working...
      X