Announcement

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

  • Stacked bar graph for multiple policies for states across years

    Is there any efficient way of illustrating these following policies in a stacked bar graph like the provided code I'm attaching here? Any advice? I'm getting invalid syntax [ r (198) ] for using this attached code for these policies.

    I want to show over the years the total number of states took these policies in. a stacked bar graph.

    Code:
    gen min_wage=0
    
    replace min_wage = 1 if year>=2015  & (statefip==2 /*alaska*/)
    replace min_wage = 1 if year>=2015  & (statefip==5 /*Arkansas*/)
    replace min_wage = 1 if year>=2013  & (statefip==4 /*Arizona*/)
    replace min_wage = 1 if year>=2015  & (statefip==6 /*California*/)
    replace min_wage = 1 if year>=2015  & (statefip==9 /*Connecticut*/)
    replace min_wage = 1 if year==2015  & (statefip==8 /*Colorado*/)
    replace min_wage = 1 if year>=2014  & (statefip==11 /*Dis.of Col*/)
    
    gen min_wagead=0
    
    replace min_wagead = 1 if year>=2018  & (statefip==32)
    replace min_wagead = 1 if year>=2017  & (statefip==35)
    replace min_wagead = 1 if year>=2017  & (statefip==34 )
    replace min_wagead = 1 if year>=2015  & (statefip==36 )
    replace min_wagead = 1 if year>=2018  & (statefip==39 )
    replace min_wagead = 1 if year==2019  & (statefip==48)
    replace min_wagead = 1 if year>=2019  & (statefip==51)
    This is the command I'm using for illustration of a stacked bar graph for these policies :

    Code:
    graph bar statefip if min_wage==`1' & min_wagead==`1', over(year) bar(1, color(usaid_red) lcolor(black)) bar(2, color(usaid_darkgray) lcolor(black)) ///
                        blabel(total, position(inside) format(%2.0f) color(white) /*size(5)*/) stack ///
                        title("# of states using minimum wage") ///
                        note("Source: Minimum wage) ///
                        legend(label(1 "# Minimum wage initial") label(2 "# Minimum wage later")) graphregion(color(white))
    Last edited by Tariq Abdullah; 23 Oct 2021, 12:27.

  • #2
    One reason for invalid syntax might be your use of

    Code:
    `1'
    which will legal if and only if you have defined local macro named 1 in the same space as your code.

    If you mean just the number 1 then say so.

    Comment


    • #3
      Yeah, now that you kindly point it out I see where I went wrong. Very gracious of you for taking the time to steer me in the right direction. I so appreciate your time and patience !

      Comment

      Working...
      X