Hi everyone, I have the following loop, with aim to create and save a series of pie charts.
In the subtitle, I want to recall and show the value of the costofhealthydiet variable (numeric, within many decimals), captured by the `healthydiet' local. This works, but the format of the costofhealthydiet variable is lost, and in the subtitle displays the full value of costofhealthydiet, with all the decimals instead of only 2 (as done by the command "format %3.2f costofhealthydiet"), which is what I'd like. If I use the format line inside the loop, it doesn't work.
Can somebody help with keeping the 2 decimal format also in the graph subtitle?
Thanks a lot!
Here's the code:
format %3.2f costofhealthydiet
forvalues i = 1/46 {
local section_label : label (section) `i'
local healthydiet = costofhealthydiet
graph pie costperdayadjusted if section == `i', over(item_name) sort(foodgroup) ///
title("Food items selected in `section_label''s HDB", size(medium)) ///
subtitle("Cost share over a full basket cost of `healthydiet'", size(vsmall)) ///
note("The cost share is calculated based on the (adjusted) cost of each food item selected in the Healthy Diet Basket. The HDB is calculated at the section level, for all outlet types.", size(vsmall)) ///
plabel(_all percent, size(tiny)) legend(size(vsmall) symxsize(*0.5))
graph save "$data_outputs/graphs/pie charts/GPH/section`i'.gph", replace
graph export "$data_outputs/graphs/pie charts/PNG/section`i'.png", replace
}
In the subtitle, I want to recall and show the value of the costofhealthydiet variable (numeric, within many decimals), captured by the `healthydiet' local. This works, but the format of the costofhealthydiet variable is lost, and in the subtitle displays the full value of costofhealthydiet, with all the decimals instead of only 2 (as done by the command "format %3.2f costofhealthydiet"), which is what I'd like. If I use the format line inside the loop, it doesn't work.
Can somebody help with keeping the 2 decimal format also in the graph subtitle?
Thanks a lot!
Here's the code:
format %3.2f costofhealthydiet
forvalues i = 1/46 {
local section_label : label (section) `i'
local healthydiet = costofhealthydiet
graph pie costperdayadjusted if section == `i', over(item_name) sort(foodgroup) ///
title("Food items selected in `section_label''s HDB", size(medium)) ///
subtitle("Cost share over a full basket cost of `healthydiet'", size(vsmall)) ///
note("The cost share is calculated based on the (adjusted) cost of each food item selected in the Healthy Diet Basket. The HDB is calculated at the section level, for all outlet types.", size(vsmall)) ///
plabel(_all percent, size(tiny)) legend(size(vsmall) symxsize(*0.5))
graph save "$data_outputs/graphs/pie charts/GPH/section`i'.gph", replace
graph export "$data_outputs/graphs/pie charts/PNG/section`i'.png", replace
}

Comment