Announcement

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

  • How to generate multiple margins plot using "marginsplot"?

    Hi,

    I am running a logit model, for which I am calculating the margins. I need margins for all the explanatory variables, but the "marginsplot" command returns an error. The error is as follows: option dydx() not allowed

    The codes that I am using:

    Code:
    logit outcome_dummy log_base_avgincome1 i.incomechangecat base_hhsize abschange_hhsize i.castecat i.religioncat i.marital_status_category i.educat i.agecat  if regioncat==2, vce(cluster hrx)
    margins, dydx(*) post
    marginsplot, dydx(castecat)
    Example of my data.

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte outcome_dummy double log_base_avgincome1 float incomechangecat byte(base_hhsize abschange_hhsize) float(castecat religioncat) long marital_status_category float(educat agecat)
    0 9.96716632919931 3 4  0 1 1 2 3 4
    0 10.8920989459899 3 7  0 2 1 2 1 3
    0 10.8920989459899 3 7  0 2 1 3 1 3
    0 10.8920989459899 3 7  0 2 1 3 1 3
    1 10.4389570072149 3 6 -1 1 1 2 3 4
    0 8.79444606837748 2 4  0 3 1 2 3 1
    0 9.56099724358935 2 3  0 3 2 2 3 4
    0 10.7733677865876 2 5  0 1 1 2 5 1
    0 9.45876173047466 2 5  0 1 1 2 1 5
    0 9.30177943229296 3 4  0 2 1 2 5 1
    1 9.70351106050345 2 5  0 2 1 2 4 1
    1 10.3263012989789 4 3  0 2 3 2 3 5
    0 10.3263012989789 4 3  0 2 3 1 1 1
    0  10.631386340039 2 4  0 1 3 2 5 5
    1 9.73373665291603 3 6 -1 2 2 2 3 4
    0 10.1701694058648 3 6 -2 1 1 2 1 4
    0 9.68735064724744 3 4  0 2 1 2 4 5
    0 9.81524359805304 4 9 -5 2 2 2 5 5
    0 10.2752666029895 2 3  0 3 1 2 4 4
    0 11.4470527208195 3 3  0 1 3 2 1 4
    1 9.57324586566555 3 3  0 1 1 2 4 4
    0 10.7851868396407 3 5  0 3 1 2 1 4
    end
    label values marital_status_category marital_status_category
    label def marital_status_category 1 "Divorced/Separated", modify
    label def marital_status_category 2 "Married", modify
    label def marital_status_category 3 "Unmarried", modify
    label def marital_status_category 4 "Widowed", modify

  • #2
    The -marginsplot- command does not use, nor allow you to specify, which margins to plot. That you do in the -margins- command itself. -marginsplot- then makes a plot of all the margins you calculated. If you want separate plots for each variable:

    Code:
    logit outcome_dummy log_base_avgincome1 i.incomechangecat base_hhsize abschange_hhsize i.castecat i.religioncat i.marital_status_category i.educat i.agecat if regioncat==2, vce(cluster hrx)
    foreach v of varlist log_base_avgincome1 incomechangecat base_hhsize abschange_hhsize castecat religioncat marital_status_category educat agecat {
        margins, dydx(`v')
        marginsplot, name(`v', replace)
    }
    Important: Do not use the -post- option with the -margins- command in the above code: it will clobber the regression results and after the first variable's -margins- are computed Stata will notice that it is being asked to do impossible things on subsequent iterations and the code will break.

    That said, most of these plots will be very uninteresting: a single point with error bars surrounded by axes, basically just a waste of space. Perhaps what you are looking for as a single graph that plots the marginal effects together. In that case, you would want to run a single -margins, dydx(*) post- command, store the estimates, and then use -coefplot- to get your graph.

    Comment

    Working...
    X