Announcement

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

  • Add overall p-value (using testparm) column using collect suite

    Hello,

    I have created a table using the collect suite in Stata. I want to produce a table including results from numerous univariate regressions. I would like to report the number of observations within each regression, the coefficient result and the p-value. Regarding the p-value, if its a categorical independent variable, then i would like to report the overall p-value (results usually obtained from 'testparm').

    As an example, I have the following:

    Code:
    sysuse auto, clear
    regress mpg i.foreign
    regress mpg weight
    
    table () (command result), ///
        command(e(N) _r_b _r_p: regress mpg i.foreign ) ///
        command(e(N) _r_b _r_p: regress mpg weight ) 
        
        collect layout (coleq[mpg]#colname[i.foreign weight]) (result) (), name(Table)
        
        collect style row stack, nobinder spacer 
        collect preview
    The output is:

    Code:
    ----------------------------------------
                    |  Coefficient   p-value
    ----------------+-----------------------
    Mileage (mpg)   |                       
      Car origin    |                       
        Domestic    |            0          
        Foreign     |     4.945804     0.001
      Weight (lbs.) |    -.0060087     0.000
    ----------------------------------------
    However, it doesn't show the total number of observations within each regression (I thought i'd extracted this using 'e(N)' within my command).

    Additionally, I would like to create a new column for the overall p-value (testparm results).I have tried including this using the code

    Code:
    regress mpg i.foreign
       testparm i.foreign 
        collect p_overall = (r(p)), tags(var[1.foreign]): testparm i.foreign
    My aim is for it to look like:

    Code:
    -----------------------------------------------------------
                    |  N Coefficient   p-value  overall p-value
    ----------------+------------------------------------------
    Mileage (mpg)   |                       
      Car origin    |  74                        0.001
        Domestic    |            0          
        Foreign     |      4.945804      0.001   
      Weight (lbs.) |  74  -.0060087     0.000
    -----------------------------------------------------------
    Any guidance would be much appreciated.
Working...
X