Announcement

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

  • How to masginsplot for variable subcategories

    I want to create marginsplot for this equation
    Code:
    logit diabetes i.Age i.year
    I tried
    Code:
    margins Age, at (year= 1999 2004 2007 2011 2014)
    marginsplot
    and getting this error

    Code:
    variable '2004' not found in list of covariates
    I am only being able to get the plot for Age (but want it to show the curve for all five years and not only for the entire sample)

    Code:
    margins Age
    marginsplot
    Click image for larger version

Name:	Capture.PNG
Views:	1
Size:	44.5 KB
ID:	1486008




    [CODE]
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float year byte Age int diab
    2014 3 1
    2014 6 0
    2014 5 1
    2014 1 0
    2014 3 1
    2014 4 1
    2014 6 1
    2014 6 1
    2014 1 1
    2014 5 1
    2014 2 0
    2014 5 1
    2014 2 1
    2014 6 1
    2014 3 1
    2014 2 0
    2014 3 0
    2014 2 1
    2014 4 0
    2014 1 1
    2014 4 1
    2014 3 1
    2014 2 1
    2014 1 1
    2014 1 1
    2014 4 1
    2014 2 1
    2014 5 1
    2014 4 1
    2014 7 1
    2014 2 0
    2014 3 0
    2014 6 0
    2014 4 0
    2014 2 0
    2014 4 1
    2014 4 0
    2014 6 0
    2014 2 1
    2014 7 1
    2014 4 1
    2014 5 1
    2014 4 1
    2014 3 0
    2014 5 1
    2014 5 1
    2014 5 1
    2014 5 1
    2014 7 1
    2014 3 1
    2014 5 1
    2014 3 1
    2014 6 1
    2014 4 0
    2014 7 0
    2014 5 1
    2014 6 0
    2014 5 1
    2014 5 1
    2014 2 1
    2014 1 0
    2014 7 1
    2014 4 1
    2014 5 1
    2014 4 1
    2014 5 1
    2014 6 1
    2014 3 1
    2014 6 1
    2014 3 0
    2014 7 1
    2014 7 1
    2014 6 1
    2014 3 1
    2014 3 1
    2014 3 1
    2014 7 1
    2014 4 1
    2014 6 1
    2014 4 1
    2014 3 1
    2014 2 1
    2014 3 1
    2014 1 0
    2014 3 1
    2014 4 1
    2014 5 1
    2014 6 0
    2014 4 1
    2014 4 1
    2014 5 1
    2014 6 1
    2014 3 1
    2014 4 1
    2014 1 1
    2014 3 1
    2014 5 1
    2014 3 1
    2014 7 1
    2014 2 1
    end
    Last edited by Sonnen Blume; 01 Mar 2019, 09:10.

  • #2
    The syntax of -marginsplot- requires that any specified list of numeric values (as opposed to just a single number) be enclosed in parentheses. Thus it should be:
    Code:
    margins Age, at (year= (1999 2004 2007 2011 2014))
    In the future, please bear in mind that the purpose of giving example data is to enable those who want to help you to work with a replica of your data to help you solve the problem. So it is important that the example you post be suitable for use with the code you are asking for help with. In your case, the code refers to a variable, diabetes, which does not exist in your example data set. (Presumably it is the variable named diab that you have in mind.) And, it is not possible to run the kind of -margins- and -marginsplot- commands you want in your example because all of your example data has year = 2014. Going forward, please be sure that the data example you post is suitable for use with the code you want to troubleshoot.

    Comment


    • #3
      Originally posted by Clyde Schechter View Post
      The syntax of -marginsplot- requires that any specified list of numeric values (as opposed to just a single number) be enclosed in parentheses. Thus it should be:
      Code:
      margins Age, at (year= (1999 2004 2007 2011 2014))
      In the future, please bear in mind that the purpose of giving example data is to enable those who want to help you to work with a replica of your data to help you solve the problem. So it is important that the example you post be suitable for use with the code you are asking for help with. In your case, the code refers to a variable, diabetes, which does not exist in your example data set. (Presumably it is the variable named diab that you have in mind.) And, it is not possible to run the kind of -margins- and -marginsplot- commands you want in your example because all of your example data has year = 2014. Going forward, please be sure that the data example you post is suitable for use with the code you want to troubleshoot.
      Thanks so much Clyde for the quick guide!
      I'll bear the instruction in mind for next posts.

      Comment

      Working...
      X