Announcement

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

  • Margins Problem

    Hi you guys,

    I'm having a problem with the margins command. Suppose I have the following commands:
    Code:
    sysuse auto
    logit foreign rep78 mpg
    Then, I would like to estimate the margins of rep78 like this:
    Code:
    margins rep78
    Instead of retrieving the margins for all the possible rep78 values I always receive the same response:
    Code:
    factor 'rep78' not found in list of covariates
    r(322);
    Am I using the command wrongly or is there another problem? I give this simple example, because it doesn't matter which dataset I use. I think this is a problem because as I looked throughout the tutorials, this command should work. Currently I'm working on a STATA 13 license, flavour IC. Does anyone know what is going on?

    Thank you so much!

  • #2
    Do you want to treat rep78 as a categorical or as a continuous variable? You are treating it as continuous. If you want to treat it as categorical, the commands should be something like

    sysuse auto
    logit foreign i.rep78 mpg
    margins rep78

    If you want to treat it as continuous, try

    sysuse auto
    logit foreign rep78 mpg
    margins, dydx(rep78)

    For an overview of margins, see

    http://www3.nd.edu/~rwilliam/stats3/Margins01.pdf
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      And to add one more reference to Richard's response, if you don't recognize the syntax
      Code:
      i.rep78
      that is "factor variable" notation, by which you instruct Stata to consider a variable categorical rather than continuous. This is all described in
      Code:
      help factor variables
      .

      Comment


      • #4
        Thank you, Richard!
        I was also using the prefix "xi:" in my command before the "i." in my dataset, and that was preventing the margins command from working.

        Thank you!

        Comment


        • #5
          Hello Eduardo,

          Welcome to the Stata Forum.

          Since in your mock example you forgot to underline that you were

          [...] also using the prefix "xi:" in my command before the "i." in my dataset, and that was preventing the margins command from working.
          For the forfhcoming messages, in order to facilitate helpful and prompt advices, I share a specific recommendation in the FAQ:

          12.1 What to say about your commands and your problem

          Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!
          I kindly reminded this recommendation because it is really important to streamline collaborative work.

          Kind regards,

          Marcos
          Best regards,

          Marcos

          Comment

          Working...
          X