Announcement

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

  • twoway connected line graph with multiple if statement

    I want to plot connected line graph to represent the before after pattern of a policy implemented in 2014.
    I want to see the trend of gender(a dummy variable, male==0, female==1) in the expansionary state(which is another indicator variable, expansionary state==1 vs non expansionary state==0). So this is a nested if condition.
    How do i incorporate this two conditions to plot a two way connected graph for the gender in the expansionary state?

    My current code is the following which is giving an error as "invalid syntax"
    by year gender, sort: egen mean_enroll=mean(enrollment)
    twoway (connected mean_enroll year if gender==1, ms(O)) (connected mean_enroll year if gender==0, ms(Oh)), xline(2014) legend(label(1 "Female") label(2 "Male")) , by(expansionary_state)

  • #2
    Too many commas -- in essence all option calls should go after a single comma (that's not the whole truth, but it is an excellent starting point). With some other simplifications I suggest

    Code:
    twoway connected mean_enroll year if gender==1, ms(O) || connected mean_enroll year if gender==0, ms(Oh)  xline(2014) legend(order(1 "Female" 2 "Male"))  by(expansionary_state)
    Last edited by Nick Cox; 10 May 2020, 10:54.

    Comment


    • #3
      How do I label the xline? I mean the graphs are by expansionary_state which is a binary variable. So in the xline instead of 0 and 1 how do I label in sentences?
      Example: 0==expansionary state
      1==non expansionary state

      Comment


      • #4
        Thanks Nick. Can you help me with the labels?
        How do I label the xline? I mean the graphs are by expansionary_state which is a binary variable. So in the xline instead of 0 and 1 how do I label in sentences?
        Example: 0==expansionary state
        1==non expansionary state

        Comment


        • #5
          I can't remember if I saw #3 in July or not but #3 and #4 seem different questions

          To see text for each panel defined by by() define value labels for expansionary_state

          Code:
          label def expansionary_state 1 "yes" 0 "no" 
          label val expansionary_state expansionary_state
          or whatever you want (but don't make the labels too long because otherwise they may not fit well). Once value labels are defined they should be picked up automatically by the graph command here.

          On #4 I am less clear what you want. xline(2014) won't engender an axis label which you may need to add yourself.

          Comment

          Working...
          X