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
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
Comment