Announcement

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

  • Plotting nonlinear predicted probabilities from multivariate model against a continous variable

    Apologies if this has already been answered, but I have been unable to find a clear answer/I am not exactly sure what I am looking for. I would like to plot nonlinear predicted probabilities from a multivariate model against a continous variable included in the model at two different levels of an indicator variable. I estimate predicted probabilties of students passing an exam. Here's the model I'm fitting:

    Code:
     areg pass i.low_income std_prior_test_score std_prior_test_score_sq std_prior_test_score_cubed other_covs, absorb(fixedeffect)
    , where pass is a binary dummy variable =1 if a student passed the exam, low-income is a binary dummy =1 if a student is classified as low-income, std_prior_test_score is the student's standardized test score on a prior exam, std_prior_test_score_sq is that score squared and std_prior_test_score_cubed cubed.

    I want to plot the predicted probability of passing against std_prior_test_score at the means of the other covariates. I have played around with the lpoly and margins commands, but have run into issues. Here's what I've done with margins:
    Code:
    margins i.lowinc_max, at(std_prior_test_score_sq(-2.5(.1)1.5)) atmeans
    marginsplot
    and obtained the following:
    Click image for larger version

Name:	Screenshot 2022-02-23 181200.jpg
Views:	1
Size:	39.6 KB
ID:	1651739



    Of course, I'm hoping to obtain the nonlinear relationship with the x-axis variable. Am I able to obtain this nonlinear predictions using the margins command? Or perhaps using a combination of predict and lpoly?

    Eventually, I would like to plot the predictions from the following model as well:

    Code:
     areg pass i.low_income i.low_income#c.std_prior_test_score i.low_income#c.std_prior_test_score_sq i.low_income#c.std_prior_test_score_cubed other_covs, absorb(fixedeffect)
    I appreciate any and all input. I'm sure there exists an easy solution that I am just unfamilar with. Thank you.

  • #2
    Your problem is that you are not representing the higher power terms in a way that enables Stata to work with it properly. There is no way for Stata to know that std_prior_test_score_sq is the square of std_prior_test_score, nor that std_prior_test_score_cubed is its cube. As far as Stata is concerned, these are just three unrelated variables. The only way Stata would treat them as somehow similar is that you could refer to them in commands jointly as std_prior_test_score*

    To get what you need, you have to re-run the regression as
    Code:
    areg pass i.low_income c.std_prior_test_score##c.std_prior_test_score##c.std_prior_test_score other_covs, absorb(fixedeffect)
    Then when you run your -margins- command, Stata will recognize that std_prior_test_score was entered into the model as a cubic polynomial and will compute your predictive margins accordingly.

    For more information about this kind of factor variable notation, see -help fvvarlist-.

    Comment


    • #3
      Thank you so much, Clyde! This is exactly what I needed.

      Comment

      Working...
      X