I am using STATA 14.2 with the user written program catplot (ssc install catplot). I have participants categorized into 4 different groups according to kidney function. I want to plot percentages of participants with certain symptoms. These symptom cateories, e.g. dyspnea yes/no are sub-divided into grades of dyspnea.
I want to plot categories no dyspnea, yes dyspnea and further different grades of dyspnea for each of the 4 groups. I have created an (not so illustrative) example in with the auto database - rep78 is quite unequal distributed across the different makes of cars.
Code:
clear sysuse auto sort foreign *Make subcategories for foreign gen fctr = 0 if foreign == 0 replace fctr = 1 if strpos(make, "Fiat") replace fctr = 2 if strpos(make, "Datsun") | strpos(make, "Honda") | strpos(make, "Mazda") |strpos(make, "Toyota") | strpos(make, "Subaru") replace fctr = 3 if strpos(make, "Renault") | strpos(make, "Peugeot") replace fctr = 4 if strpos(make, "VW") | strpos(make, "Audi") | strpos(make, "BMW") replace fctr = 5 if strpos(make, "Volvo") la define fctr_la 0 "Domestic" 1 "Italy" 2 "Japan" 3 "France" 4 "Germany" 5 "Sweden" la val fctr fctr_la
Code:
catplot foreign, over(fctr , label(labsize(vsmall))) over(rep78) percent(rep78) blabel(bar, format(%8.1f)) asyvars /// title("Repairs by Origin")
Array
Inspired by this thread: https://www.stata.com/statalist/arch.../msg01100.html
I then proceeded with the following to add total percentages of foreign cars in a 6th category
Code:
preserve local N = _N expand 2 //double observations gen byte new = _n > `N' //indicator variable shows which are the new dublettes. replace fctr = 6 if new & foreign == 1 //new category label label define fctr_la 6 `""All Foreign""', add catplot foreign, over(fctr , label(labsize(vsmall))) over(rep78) percent(rep78) blabel(bar, format(%8.1f)) asyvars /// title("Repairs by Origin") restore
Array
As one can see, this approach is misguided because, contrary to the inspiring thread, I am dealing with percentages, which are off by factor 0.5 (except for domestic) due to the expansion of the dataset.
I cannot seem to see my way out of it. Maybe this is just impossible to combine in a single graph? Editing barlabels does not seem possible either as catplot is not build upon 2way plots, but bar plots.
Any suggestions would be greatly appreciated.
0 Response to Catplot - plotting subcategories or subgroups along with main categories
Post a Comment