Announcement

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

  • Collect margins with continuous regressors

    I would like to -collect- some -margins- and present them in a clear (and good-looking) table. The margins command below is used after a conditional logit model. The variables PeerInv, CT and HCT are continuous. As shown in the call, -margins- estimates average marginal effects (AMEs) for PeerInv at different levels of CT and HCT.

    Code:
    collect: margins, dydx(PeerInv) at(CT=($CT_low $CT_mean $CT_high) HCT=($HCT_low $HCT_high)) post
    What I'd like to accomplish is (conceptually) fairly simple: create a table with PeerInv AMEs, at low, mean, and high values of CT (on the rows) and low and high values of HCT (on the columns). I thought that one of the following -collect layout- commands would have done the job, but neither of them worked - I get the message "Your layout specification does not identify any items."

    Code:
    collect layout (CT) (HCT) (result[_r_b])
    
    collect layout (CT[$CT_low $CT_mean $CT_high]) (HCT[$HCT_low $HCT_high]) (result[_r_b])
    Any help is greatly appreciated.

  • #2
    Without a dataset to go with your code it is difficult to help.

    Here is an example based on the information you provide, except I use the auto data and logit instead of clogit to fit the model.
    Code:
    sysuse auto
    
    logit for mpg turn trunk
    
    sum turn
    global turn_low : display %9.2f r(min)
    global turn_mean : display %9.2f r(mean)
    global turn_high : display %9.2f r(max)
    global turn_list $turn_low $turn_mean $turn_high
    
    sum trunk
    global trunk_low : display %9.2f r(min)
    global trunk_mean : display %9.2f r(mean)
    global trunk_high : display %9.2f r(max)
    global trunk_list $trunk_low $trunk_mean $trunk_high
    
    collect : ///
    margins, ///
            dydx(mpg) ///
            at(turn=($turn_list) trunk=($trunk_list))
    
    * add tags for turn and trunk levels that correspond with the levels of
    * the _at dimension 
    local at 0
    foreach turn of global turn_list {
        foreach trunk of global trunk_list {
            local ++at
            collect addtags turn[`turn'] trunk[`trunk'], fortags(_at[`at'])
        }
    }
    
    * show header labels
    collect style header turn trunk, title(label)
    * center column header label
    collect style column, dups(center)
    * add format for cell values
    collect style cell result[_r_b], nformat(%9.3f)
    
    collect layout (turn) (trunk) (result[_r_b])
    Here is the resulting table.
    Code:
    -----------------------------------------
                      | Trunk space (cu. ft.)
                      |    5.00  13.76  23.00
    ------------------+----------------------
    Turn circle (ft.) |                      
      31.00           |  -0.002 -0.002 -0.003
      39.65           |  -0.011 -0.010 -0.009
      51.00           |  -0.000 -0.000 -0.000
    -----------------------------------------

    Comment


    • #3
      Jeff, you are a star. It had not occurred to me that one possible solution would be to add additional tags. -collect- is a great family of commands. But I still have to get the hang of it. Thanks so much for the help.

      Comment

      Working...
      X