Announcement

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

  • Using fmlogit with an independent variable modeled as a spline

    Dear all,
    I have a few questions related to the user-written program fmlogit. I'm trying to fit a model with four proportions adding up to 1 as dependent variables, a continuous variable modeled as restricted cubic spline with 4 knots as independent variable, and a few additional control variables.

    My first question is the following: after fitting fmlogit and looking at marginal effects, is there a way to obtain the multi-df p-value for the combined effect of the spline variable on each proportion? In the example below, the spline components show p-values of 0.089, 0.257 and 0.267, but I would be interested in the p-value of the overall effect of spline on governing

    use http://fmwww.bc.edu/repec/bocode/c/citybudget.dta, clear

    mkspline spl_popdens = popdens, cubic nknots(4)

    fmlogit governing safety education recreation social urbanplanning, eta(spl_* minorityleft noleft houseval)

    margins, dydx(spl_*) predict(outcome(governing))

    My second question is: is it expected that an independent variable has a significant p-value for its coefficient but not for the marginal effect or vice versa? In the example above, the p-value for the variable noleft on safety is 0.191, but the p-value from:

    margins, dydx(noleft) predict(outcome(safety))

    is <0.001

    Finally, how would you report the effect of a spline variable on each proportion? I guess a plot with predicted probabilities for each outcome as a function of the independent variable is the only way to proceed?

    Many thanks,
    Manuel

  • #2

    1. Use -lincom- after -margins-
    2 Marginal effects are typically non-linear functions of the parameters so even if a coefficient is statistically significant it does not guarantee the marginal effects will be significant.
    3. Below is example of adjusted predictions following this example https://www.statalist.org/forums/for...-cubic-splines

    Code:
    use http://fmwww.bc.edu/repec/bocode/c/citybudget.dta, clear
    
    mkspline spl_popdens = popdens, cubic nknots(4) display
    
    fmlogit governing safety education recreation social urbanplanning, /// 
     eta(spl_* minorityleft noleft houseval)
     
    gen popdens2 = int(popdens)
    margins,  atmeans over(popdens2) predict(outcome(governing))
    marginsplot, recastci(rarea) ciopts(pstyle(ci) color(%35)) /// 
      plotopts(msymbol(i))  scheme(black_tableau)
    
    margins, dydx(spl_*) predict(outcome(governing)) post
    lincom spl_popdens1 + spl_popdens2 + spl_popdens3
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	43.0 KB
ID:	1647877

    Comment


    • #3
      Thank you so much Scott for your help. The code you provide works perfectly, however when I apply it to my data I get a jagged plot like this:

      Click image for larger version

Name:	Graph.jpg
Views:	1
Size:	27.0 KB
ID:	1647889


      This only occurs when covariates are included in the fmlogit model, otherwise I get a smooth spline as expected. Any thoughts? Also, for the sake of generalizability, would your approach work if the independent variable could not be turned into an integer (e.g. values between 0.01 and 0.1)?

      Thanks again,
      Manuel
      Attached Files

      Comment


      • #4
        It appears that -atmeans- with the -over()- option is taking the mean for each group. One needs to use the overall means -atmeans((omeans) varlist)-

        Compare:
        Code:
        use http://fmwww.bc.edu/repec/bocode/c/citybudget.dta, clear
        replace popdens = popdens*100
        mkspline spl_popdens = popdens, cubic nknots(4) display
        
        qui fmlogit governing safety education recreation social urbanplanning, /// 
         eta(spl_* minorityleft noleft houseval)
         
        gen popdens2 = int(popdens)
        qui margins,  at((omean) minorityleft noleft  houseval ) /// 
         over(popdens2) predict(outcome(governing))
        marginsplot, recastci(rarea) ciopts(pstyle(ci) color(%35)) /// 
          plotopts(msymbol(i))  title(At Overall Means) /// 
          scheme(black_tableau)   name(gr1,replace)
        
        qui margins, atmeans  /// 
         over(popdens2) predict(outcome(governing))
        marginsplot, recastci(rarea) ciopts(pstyle(ci) color(%35)) /// 
          plotopts(msymbol(i)) title(At Means for Each Group) /// 
          scheme(black_tableau) name(gr2,replace)
        
        graph combine gr1 gr2, row(1) ycommon
        Click image for larger version

Name:	Graph.png
Views:	1
Size:	76.7 KB
ID:	1647895

        Comment


        • #5
          It works perfectly, thank you!

          Comment

          Working...
          X