Announcement

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

  • Two line frequency graph help

    Hello everyone.

    I've been trying to figure this out on my own but I haven't been very successful.
    I am working on trying to make a graph of individuals killed over the last 4 years either with mental health diagnosis or without. What I want is something like this

    https://www.stata.com/support/faqs/g...id-line-graph/

    So the frequency of individuals killed by year on the Y-axis with the two lines showing those with mental illness and those without and the years on the X-axis. but every time I try to do something I get something like these.

    (I used twoway (line MI Year, sort) for this one)


    and this line MI_NP MI_Present Year for this graph


    I can not for the life of me figure out what is wrong. I do have the Mental illness variable set up as a dummy variable and the years are broken down into four groups. I have been wondering if I need to fix something in the way the data is set up or if I am just typing commands for what I want wrong.

    Any direction you could give me would be greatly appreciated.

  • #2
    Welcome to the Stata Forum / Statalist,

    Please read the FAQ. There you will find information about sharing data/command/output. Also, tips on how to share figures.

    This is the best approach to entice an insightful reply to the query.
    Best regards,

    Marcos

    Comment


    • #3
      Your variables MI MI_Present MI_NP are all evidently 1 or 0 (or possibly constant) and the graphs reflect that. It's pretty clear that you want to count groups somehow, but I am not easily able to guess precisely how without a data example. However

      Code:
      contract MI Year 
      line _freq Year if MI == 1 || line _freq Year if MI == 0 , legend(order(1 "whatever" 2 "something else"))
      may help

      Comment

      Working...
      X