Announcement

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

  • How to add markers/symbols to a two way bar?

    Hi! I am trying to add symbols/markers at specific points along my bars that say the title of the variable the bar is measuring. Does anyone know the syntax for adding symbols on top of bars? I tried inputted a symbol variable in my input data and then using scatter to label the points but the scales were all messed up then. Here is the code for context:

    clear

    /* <cd ""> */

    import delimited "policybars\data\Small_group_offer_rates_data. csv"

    * Define the variable of interest that is being looked at with policy changes
    local usevar "v2"

    * DO NOT CHANGE - Sample data generation
    input str30 year1 start_year end_year /*symbol*/
    "Silver_Loading" 2018 2018 2030 /*90*/
    "Enhanced_PTCs" 2022 2022 2025 /*80*/
    "Medicaid_Cont_Eligibility" 2020 2020 2023 /*70*/
    "Medicaid_unwinding" 2023 2023 2024 /*60*/
    end

    /*Do not change any of the code below until you get to the next section that says 'Twoway'" */

    *******
    * establishing the lowest value of the imputed data set's variable for shading *
    gen minrow = min(v2, v3, v4, v5,v6)

    * establishing the highest value of the imputed data set's variable for shading *
    gen maxrow = max(v2, v3, v4, v5,v6)

    * summarize what the lowest value is *
    summarize minrow
    * making local variable to use for shading the base of the shadowed bars *
    local graphmin = r(min)
    display `graphmin'

    * summarize what the highest value is *
    summarize maxrow
    * making local variable to use for shading the height of the shadowed bars *
    local graphmax = r(max)

    *creating silver loading shading*
    gen Silver_Loading = .
    replace Silver_Loading = `graphmax' if year == 2018 /*& year <=2026 */

    gen Enhanced_PTCs = .
    replace Enhanced_PTCs = `graphmax' if year == 2022 /*| year == 2025*/

    gen Medicaid_Cont_Eligibility = .
    replace Medicaid_Cont_Eligibility = `graphmax' if year == 2023 /*| year == 2026 */

    * creating medicaid unwinding shading
    gen Medicaid_unwinding = .
    replace Medicaid_unwinding = `graphmax' if year == 2023 /* | year == 2024 */

    *creating continuous enrollment eligibility shading
    gen Continuous_Enrollment_FPL150 = .
    replace Continuous_Enrollment_FPL150 = `graphmax' if year == 2023 | year == 2026
    *******


    /* gen Silver_Loading_L = 90 if year == 2018
    destring Silver_Loading_L, replace
    *rename Silver_Loading_L "Silver Loading Begins"*/




    * Input the ytitle to what you want your Y axis to be (what you want graphed) and comment our the policies you do not need to see on the final graph */
    * VERY IMPORTANT: Change the variable after the command LINE on line 107 to the variable you are interested in from your data set *

    twoway ///
    (bar Silver_Loading year, fcolor(bluishgray) lcolor(bluishgray) lpattern(solid) base(0) barwidth(0.3)) ///
    (bar Enhanced_PTCs year, fcolor(bluishgray) lcolor(bluishgray) lpattern(solid) barwidth(0.3)) ///
    (bar Medicaid_Cont_Eligibility year, fcolor(bluishgray) lcolor(bluishgray) lpattern(solid) fintensity(40) barwidth(0.3)) ///
    (bar Medicaid_unwinding year, fcolor(red) lcolor(red) lpattern(solid) fintensity(40) barwidth(0.05)) ///
    *(scatter symbol v2, color(blue)) *
    (line v2 year, color(black) lpattern(solid) lw(thick)), ///
    xtitle("Years") ///
    ytitle("Offer Rates for Firms w/ <10 Employees") ///
    xlab(2010(2)2030) ///
    ylab(, angle(horizontal)) ///
    ttext(90 2018 "Silver Loading Begins", place(w) size(small)) ///
    ttext(80 2020 "Medicaid Continuous Eligibility Begins", place(e) size(small)) ///
    ttext(70 2023 "Medicaid Unwinding Begins", place(w) size(small)) ///
    ttext(60 2022 "Enhanced PTCs Begins", place(e) size(small)) ///
    Graph.gph


  • #2
    Try orienting the text vertically. For your future posts, present data examples using dataex and images in .PNG format as recommended in FAQ Advice #12.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float Silver_Loading int year float(Enhanced_PTCs Medicaid_Cont_Eligibility Medicaid_unwinding v2)
       . 2011    .    .    .   36
       . 2012    .    .    . 35.3
       . 2013    .    .    . 36.2
       . 2014    .    .    . 32.9
       . 2015    .    .    . 30.4
       . 2016    .    .    . 28.4
       . 2017    .    .    . 30.8
    99.8 2018    .    .    . 30.4
       . 2019    .    .    . 31.2
       . 2020    .    .    . 30.2
       . 2021    .    .    . 31.1
       . 2022 99.8    .    . 33.4
       . 2023    . 99.8 99.8 33.4
    end
    
    
    twoway ///
    (bar Silver_Loading year, fcolor(bluishgray) lcolor(bluishgray) lpattern(solid) base(0) barwidth(0.3)) ///
    (bar Enhanced_PTCs year, fcolor(bluishgray) lcolor(bluishgray) lpattern(solid) barwidth(0.3)) ///
    (bar Medicaid_Cont_Eligibility year, fcolor(bluishgray) lcolor(bluishgray) lpattern(solid) fintensity(40) barwidth(0.3)) ///
    (bar Medicaid_unwinding year, fcolor(red%40) lcolor(red%40) lpattern(solid) fintensity(40) barwidth(0.05)) ///
    (line v2 year, color(black) lpattern(solid) lw(thick)), ///
    xtitle(" ") ///
    ytitle("Offer Rates for Firms w/ <10 Employees") ///
    xlab(2010(2)2024) ///
    ylab(, angle(horizontal)) ///
    ttext(70 2018 "Silver Loading Begins", place(c) size(small) orientation(vert)) ///
    ttext(50 2020 "Medicaid Continuous Eligibility Begins", place(c) size(small) orientation(vert)) ///
    ttext(70 2023 "Medicaid Unwinding Begins", place(c) size(small) orientation(vert)) ///
    ttext(70 2022 "Enhanced PTCs Begins", place(c) size(small) orientation(vert)) ///
    leg(off) plotregion(margin(zero))
    Res.:
    Click image for larger version

Name:	Graph.png
Views:	1
Size:	30.5 KB
ID:	1745102


    Last edited by Andrew Musau; 29 Feb 2024, 11:40.

    Comment

    Working...
    X