April 22, 2018

Stopping midway while running a do-file

If you're like me who always use a do-file even when running short analyses (e.g. just one chart! -- it helps if you always have a record of what you're doing; I even put a time stamp on mine), more often than not you want to see ONLY the result of some codes found in the middle of a do-file. For instance, in the middle of the do-file, you have codes for running a regression. If you just want to see the regression results without seeing the output, you have several options.

If you have more patience than me, you can just highlight only the set of codes you want to see the results of (the regression codes for instance) and then type Ctrl+D to run the codes. But maybe this is cumbersome because before running the regression, you may need to prepare the data first, and maybe generate new variables. So you would need to go back further and highlight a few more lines of codes.

An alternative would be not to highlight anything and just simply click Ctrl+D. Of course, this would run the whole do-file so an additional step for you is to look at the results window and search for the regression results. But with all the output of other analyses included in the do-file also presented in the results window, I'm sure you will soon start to think there should be an easier way to do this.

And that easier way is to use "/*". Putting these two characters after the codes for the analysis you want to see (the regression codes in my example) would suppress the results of the rest of the analyses in the do-file. Yes, you'll still see the results of the analyses at the earlier portion of the do-file (before the regression analysis in my example), but at least all you need to do is just look for the start of where the results are suppressed, and before that you will find the analysis you want to see (i.e., the regression results).

Then again, if you're like me, I hate that I have to scroll back up, especially if the do-file is horribly long.

This brings us to what I think is the best and simplest solution. Just use "exit". Write this command after the codes you want to see and when you type Ctrl+D without highlighting any codes, the do-file will run and end immediately after the output you are looking for is presented in the results window. No need for scrolling up and down. Simple as that.

exit

April 19, 2018

Changing x-axis labels in graph bar charts

The graph bar and twoway bar may seem like commands that generate the same thing: bar charts. But they are actually different, and one has advantages over the other. Similarly, one also has disadvantages over the other. You can easily use stacked charts with graph bar for example.

graph bar domgheche1 shiche1 oopche1 extche1 othche1 if country=="Philippines" ///
, ///
over(year, label(labsize(small))) ///
stack ///
outergap(75) ///
bar(1, color(ltkhaki)) ///
bar(2, color(khaki)) ///
bar(3, color(red)) ///
bar(4, color(ltblue)) ///
subtitle("Source of health expenditure, Philippines") ///
ytitle("Share (%)" " ") ///
legend(order(1 "Domestic" "government" 2 "SHI and" "compulsory" "prepayment" 3 "OOP" 4 "External" 5 "Other") pos(6) row(1) symxsize(6) size(small))


One of the problems you may encounter (especially if you chart multiple instances, years in this case, of the variables you are graphing), is getting a very crowded x-axis with the many labels (again in this case, years). One way to resolve this issue is that you can opt not to show all the labels and instead only a few. For example, you might want to show only 5-year labels (2000, 2005, 2010, and 2015). You can do this by using the relabel option (highlighted below).

graph bar domgheche1 shiche1 oopche1 extche1 othche1 if country=="Philippines" ///
, ///
over(year, relabel(2 " " 3 " " 4 " " 5 " " 7 " " 8 " " 9 " " 10 " " 12 " " 13 " " 14 " " 15 " ") label(labsize(small))) ///
stack ///
outergap(75) ///
bar(1, color(ltkhaki)) ///
bar(2, color(khaki)) ///
bar(3, color(red)) ///
bar(4, color(ltblue)) ///
nofill ///
subtitle("Source of health expenditure, Philippines") ///
ytitle("Share (%)" " ") ///
legend(order(1 "Domestic" "government" 2 "SHI and" "compulsory" "prepayment" 3 "OOP" 4 "External" 5 "Other") pos(6) row(1) symxsize(6) size(small))


Keep in mind that with graph bar, you are graphing over categorical values of the x-variable. So when relabeling, the bars are assigned the values 1, 2, 3, etc. from left to right. So you have to identify which number you are relabeling. In the example above encompassing 16 years, all categories of years are relabeled to missing except for 1 (for 2000), 6 (for 2005), 11 (for 2010), and 16 (for 2015).

Just to give you a background on the example above, the chart shows a breakdown of health expenditures by revenue source in the Philippines from 2000 to 2015. Health financing in any country can come from 5 revenue sources: (1) domestic government (a.k.a. tax revenue); (2) social health insurance and other compulsory prepayment; (3) out-of-pocket spending, or OOP; (4) external sources (international organizations and foreign governments); and (5) others (including other private sources). These charts are very important as part of monitoring trends of these sources, especially OOP. OOP is basically paying for health service directly "out of your pocket" right there and then. One of the tenets of Universal Health Coverage (UHC) is ensuring access to health care without facing financial hardship. Keep in mind, no one knows when you or your family member gets sick. So you will not only encounter a health shock, but also a financial shock if you have to pay for health care "out of your pocket."

Achieving UHC means that health care should either be financed by the government or through prepaid/pooling mechanisms such as SHI and other compulsory prepayment schemes. Using this chart, it is ideal that the OOP component (red bars) should be declining over time, while either domestic government or SHI (khaki bars) should be increasing over time. Are we seeing this in the Philippines? Unfortunately, not. We instead see the opposite.

The source of the data is World Health Organization's Global Health Expenditure Database.


Still fixing my blog

I've been busy with work at the World Bank so I have not gotten back to updating this blog. I didn't know that the images are down. I will work on fixing them in the next couple of days. And hopefully I can start blogging again.