Announcement

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

  • Predicted probabilities in logit regression with control variables set to mean or mode

    I have made a lot of logistic regression with one binary independent variable on a lot of different binary dependent variables. The models includes both categorical and continous control variables. The interpretation of the coefficients are not intuitive, so I want to show the predicted probabilities of the dependented variables when my independent variable is 0 and 1, repsectively, with the control variables set to mode or mean (for categorical and continous control variables, respectively).

    In the auto data, this is what I try to do:

    Code:
    sysuse auto, clear
    recode price (0/5000 = 1 "Cheap") (5001/999999 = 0 "Expensive"), gen(cheap)
    logit foreign i.cheap i.rep length
    margins cheap, at(rep=mode length=mean)
    Can anyone help with specifying the ", at"-option correctly? What I am trying to do is calcalute the predicted probabilities for 'foreign' for cheap and expensive cars when rep is at its mode and length is at its mean. Since in my real data, I have many models and varibles, manually inserting the values of the modes and means would be very time consuming.

  • #2
    You need to compute these statistics of interest beforehand:

    Code:
    sysuse auto, clear
    ssc install mmodes, replace
    mmodes rep
    sum length
    
    recode price (0/5000 = 1 "Cheap") (5001/999999 = 0 "Expensive"), gen(cheap)
    logit foreign i.cheap i.rep length
    margins cheap, at(rep=3 length=187.93)
    Best wishes

    (Stata 18.0 MP)

    Comment


    • #3
      Felix Bittmann thanks for your suggestion, but, as I wrote in my post, since in my real data, I have many models and varibles, manually inserting the values of the modes and means would be very time consuming. Therefore, computing the statistic beforehand is not a viable option.

      Comment


      • #4
        There is no option to include modes automatically. For one, modes may not be unique - so you need some criterion to select them. The option -atmeans- will automatically include means, so you can do something like

        Code:
        margins cheap, at(rep=3) atmeans
        where 3 is the mode of rep78.

        I have many models and varibles, manually inserting the values of the modes and means would be very time consuming.
        You can write a program that will compute the modes of a specified list of variables and store them in a local that you feed straight to margins, so that your command becomes

        Code:
        margins cheap, at(`modes') atmeans
        I do not have time to volunteer code at the moment.

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          There is no option to include modes automatically
          Thanks for clarifying that, got to do some programming then.

          Comment

          Working...
          X