Announcement

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

  • dual purpose refcat

    Hello Everyone,

    Please how do I use refcat to simultaneously indicate the reference (omitted) category of a categorical variable and add a row with a title for a group of variables (for example, Age for 1-9, 10-19 etc)? Here's what I'm trying to do.

    I have three models as follows:

    Code:
    sysuse auto
    
    xi: reg price mpg
    est store A
    
    xi: reg price mpg i.foreign i.rep78
    est store B
    
    xi: reg price mpg i.foreign i.rep78 displacement
    est store C
    I use refcat to indicate the reference category for the variable i.foreign and i.rep78:

    Code:
    esttab A B C, refcat(_Iforeign_1 "Domestic" _Irep78_2 "One")
    Which works.

    But attempting to create headings for i.foreign and i.rep78 using the code below does not work. Rather, it undoes the previous step.

    Code:
    esttab A B C, refcat(Domestic "Car type" One "Manufacturer")
    I tried combining the two procedures in the same refcat() statement below, but this gives only the reference categories in the output.

    Code:
    esttab A B C, refcat(_Iforeign_1 "Domestic" _Irep78_2 "One" Domestic "Car type" One "Manufacturer")
    I'll appreciate help on this. It seems like something very basic: I'm probably not saving or replacing one thing or another. Unfortunately I've been unable to figure out what's wrong.

    Thanks
    Last edited by Chibo Dike; 27 May 2018, 21:09.

  • #2
    Unless you are using a very old version of Stata, you should not be using -xi:- for this purpose. You should use factor variable notation. Nearly all estimation commands support factor-variable notation, which is simpler and much more powerful because it also enables you to use the -margins- command following estimation. There are a few exotic situations where -xi:- is still useful, but they are rare, and most are associated with older estimation commands whose functions can be better carried out with a more modern command that does use factor variable notation. So you should almost forget you ever knew about -xi:-.

    Factor variable notation also makes it very simple to specify your preferred reference categories. Read -help fvvarlist- for more information.

    Code:
    sysuse auto, clear
    
    reg price mpg
    est store A
    reg price mpg ib1.foreign ib2.rep78
    est store B
    reg price mpg ib1.foreign ib2.rep78 displacement
    est store C
    
    esttab A B C

    Comment


    • #3
      Hello Clyde

      Thanks for your reply.

      My problem is using refcat to put a title 'car type' above 0.foreign and a title 'manufacturer' above 1.rep78.
      I'll also like to have 'ref' rather than '0' for the reference category.
      Is it possible to do these simultaneously using refcat? Doing one after the other undoes the previous step.

      Click image for larger version

Name:	auto.PNG
Views:	1
Size:	6.8 KB
ID:	1446228

      Last edited by Chibo Dike; 28 May 2018, 06:18.

      Comment


      • #4
        Hi,

        like this?
        Code:
        cls
        webuse fullauto, clear
        quietly {
            eststo A: reg price mpg
            eststo B: reg price mpg ib1.foreign ib2.rep78
            eststo C: reg price mpg ib1.foreign ib2.rep78 displ
        }
        * as requested
        esttab A B C  , dropped("ref.") refcat(0.foreign "car type" 1.rep78 "repair record 1978" , nolabel)
        * more condensed version using value labels
        esttab A B C  , nobaselevels refcat(0.foreign "car type (ref.: Foreign)" 1.rep78 "repair record 1978 (ref: Fair)" , nolabel) label
        exit
        Note that rep78 does not reflect a car's manufacturer, but this is a toy example anyways.

        Regards
        Bela

        PS: Crossed with Lance Erickson's answer; his variant for regression calculation using eststo: is shorter, so I changed my example code accordingly. I agree that manually editing the labels inside of the esttab call is "a bit of a hackish way", I added a second esttab call which produces a more vertically condensed version of the same table.
        Last edited by Daniel Bela; 28 May 2018, 07:27. Reason: crossed with Lance Erickson's answer; introduced his shorter calculation method with eststo:, and added more condensed version

        Comment


        • #5
          Depending on how I want the reference category to show up in the table, I've done one of these...

          Code:
          sysuse auto, clear
          
          eststo A: reg price mpg
          eststo B: reg price mpg foreign ib2.rep78
          eststo C: reg price mpg foreign ib2.rep78 displacement
          
          esttab A B C, ///
              refcat(1.rep78 "Repair record", label(" ")) ///
              varlabels(1.rep78 "   label 1" 2.rep78 "   label 2 (reference)" 3.rep78 "   label 3" ///
                        4.rep78 "   label 4" 5.rep78 "   label 5") ///
              varwidth(25)
          
          esttab A B C, ///
              order(mpg foreign repair) ///
              drop(2.rep78) refcat(3.rep78 "   label 2", label("ref")) ///
              varlabels(repair "Repair record" 1.rep78 "   label 1" 3.rep78 "   label 3" ///
                        4.rep78 "   label 4" 5.rep78 "   label 5") ///
              varwidth(20)
          I've always felt this was a bit of a hackish way to solve this problem but it has tended to work for me. It leverages the fact that -esttab- is a wrapper for -estout-, which I tend to use anyway.

          Lance

          Comment


          • #6
            Thanks to everyone for the help.

            Comment

            Working...
            X