Announcement

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

  • Line graph - graphing percentages of a binary variable

    Hello,

    I'm trying to generate a line graph. The variables are asthma, west, east, and year. I would like the year to be on the x-axis and percentage of people who have asthma to be on the y-axis. I am trying to graph the percentage of people with asthma over the years if they live on the WEST coast and also the percentage of people with asthma over the years if they live on the EAST coast. I want to graph each separately and also one graph where there a two lines where one line=west and second line=east.

    Here's an example code.


    Code:
    * Example generated by -dataex
    clear
    input int(year asthma west east)
    2010 1 1 0
    2010 1 0 1
    2010 0 1 0
    2010 0 1 0
    2010 0 0 1
    2010 1 0 1
    2011 0 0 1
    2011 0 1 0
    2011 0 1 0
    2011 1 1 0
    2011 1 0 1
    2012 1 0 1
    2012 1 0 1
    2012 0 0 1
    2012 0 1 0
    2012 0 0 1
    2012 1 1 0
    2012 1 1 0
    2012 1 1 0
    2012 0 1 0
    2012 1 0 1
    2013 1 1 0
    2013 1 0 1
    2013 1 0 1
    2013 0 1 0
    2013 0 0 1
    2013 1 1 0
    2013 0 1 0
    2013 0 0 1
    2014 0 1 0
    2014 0 0 1
    2014 0 1 0
    2014 0 1 0
    2014 1 1 0
    2014 1 1 0
    2014 1 1 0
    2014 1 0 1
    2014 0 0 1
    2014 1 0 1
    2014 1 1 0
    2014 1 0 1
    2015 1 0 1
    2015 1 1 0
    2015 1 1 0
    2015 1 1 0
    2015 0 0 1
    2015 0 0 1
    2015 0 0 1
    2015 0 0 1
    2015 1 1 0
    2015 0 0 1
    2015 0 0 1
    2015 1 0 1
    2015 0 0 1
    2015 0 1 0
    2015 1 0 1
    2015 1 0 1
    2015 0 0 1
    end
    Last edited by Amber Pong; 11 Oct 2022, 09:33.

  • #2
    Name Unknown Please use a full real name as requested in the FAQ Advice.

    https://www.statalist.org/forums/help#realnames

    https://www.statalist.org/forums/help#adviceextras #4

    Comment


    • #3
      Nick Cox as to your second link this is not homework. This is made up data as I didn't want to post research data. I'm originally a R user so just trying to figure out STATA graphs.

      Comment


      • #4
        My apologies: the number next to the second link (Advice Extras) should have been #3 not #4. But I will add that you'll benefit from reading the entire FAQ Advice, which won't take long.

        Comment


        • #5
          Any ideas on how I should go about generating these graphs

          Comment


          • #6
            Here is some technique. See also Section 9 of https://www.stata-journal.com/articl...article=dm0055


            Code:
            egen pcAE = mean(cond(east, 100 * asthma, .)), by(year)
            egen pcAW = mean(cond(west, 100 * asthma, .)), by(year)
            egen tag = tag(year)
            line pcA* year if tag, legend(order(1 "East" 2 "West")) ytitle(% with asthma)

            Comment


            • #7
              Thanks!

              Comment

              Working...
              X