Announcement

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

  • Estimating Margins and Marginal Effects with Restricted Cubic Splines

    I am looking at the relationship of "outcome" and "variable", both of which are continuous. I have the following GLM model with a gamma distribution and a log link:
    Code:
    mkspline2 variable_knots= variable, cubic nknots(3) display
    glm outcome c.variable_knots*
    adjustrcspline
    The graph of adjusted predictions is great, but I would also like to estimate a) values of outcome at various values of variable and b) the slope of the graph between knots. Essentially, is there a way to reproduce the code below, but with my splines?
    Code:
    margins, at(variable=(0(0.1)2))
    margins, dydx(variable)
    Appreciate the help.

  • #2
    Hi Jon
    look into my commands -f_able- from SSC. It allows you to estimate marginal effects for any transformation.
    You will just need to use -f_rcspline- to create the spline functions, and add "o.variable" to the model specification.
    Fernando

    Comment


    • #3
      You can get a graph of the marginal effects with mfxrcspline which is part of the postrcspline package on SSC just as adjustrcspline and mkspline2
      ---------------------------------
      Maarten L. Buis
      University of Konstanz
      Department of history and sociology
      box 40
      78457 Konstanz
      Germany
      http://www.maartenbuis.nl
      ---------------------------------

      Comment


      • #4
        FernandoRios, I have been looking at the documentation of f_able and f_rcspline as well as other resources on google like this presentation. I'm struggling to follow how to build the model with f_rcspline and f_able.

        When I use
        Code:
        mkspline2 variable_knots= variable, cubic nknots(3) display
        two variables are created, namely variable_knots1 and variable_knots2. However, when I use
        Code:
        f_rcspline variable_knots = variable, nknots(3)
        only a single variable, variable_knots2, is created.

        Also, I tried to follow some of the examples, but I know my margins estimates are incorrect based on my original adjustrcspline.
        Code:
        glm outcome c.variable_knots*
        f_able, nl(variable_knots*)
        margins, at(variable_knots=(0(0.1)2)) nochain
        margins, dydx(variable_knots) at(variable_knots=(0.1 0.25 0.5))
        Can you provide a little more direction?

        Comment


        • #5
          Hi Jon,
          let me show you via an example (not with GLM but logit)

          Code:
          webuse mksp2, clear
          ** I do this so you can check and compare what mkspine does with what f_rcspline does
          mkspline2 xdose = dosage, nknots(3) cubic
          
          f_rcspline fdose = dosage, nknots(3)
          ** with rcspline you need to add dosage in the regression
          logistic outcome dosage fdose2
          ** then just type all the created variables (here only 1) with f_able
          f_able fdose2 , auto
          ** then just estimate marginal effects
          margins, dydx(dosage)
          margins, at(dosage=(5(5)95))
          ​​​​​​marginsplot
          margins, dydx(dosage) at(dosage=(5(5)95))
          ​​​​​​marginsplot
          Hope this helps

          Comment


          • #6
            Thank you! That example was incredibly helpful.

            Comment

            Working...
            X