Dear All,
I tried several time using different options, over(), by() but couldn't create a bar graph that I wanted. I have 2 categorical variables, occupation_before and occupation_after; both of them have same categories as shown in the sample dataset below. I wanted to create a bar where I can easily see the frequency of occupation before and after (in one chart). I tried using catplot, but I didn't find a way for two categorical variables with same categories.
I would appreciate your help in this. Also I wanted to perform similar with pie charts as well. Let me know if there is a way to do it. Thank you in advance.
I tried several time using different options, over(), by() but couldn't create a bar graph that I wanted. I have 2 categorical variables, occupation_before and occupation_after; both of them have same categories as shown in the sample dataset below. I wanted to create a bar where I can easily see the frequency of occupation before and after (in one chart). I tried using catplot, but I didn't find a way for two categorical variables with same categories.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double(occubefore occuafter) 2 6 2 2 6 2 2 1 1 1 2 2 1 2 2 2 3 3 1 1 1 1 1 2 3 3 1 1 6 6 2 2 1 2 6 4 1 1 2 2 4 4 1 1 1 1 1 1 1 1 1 1 1 4 2 2 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 1 5 6 1 1 1 1 1 6 1 1 4 6 3 2 1 1 5 6 1 6 1 1 3 3 1 1 4 1 2 1 3 3 2 2 2 2 1 1 2 2 2 6 2 2 1 1 2 2 4 4 1 1 1 1 6 6 1 1 1 2 1 1 1 1 1 1 1 1 2 6 2 2 2 5 1 4 1 1 2 2 2 6 1 1 1 1 1 1 6 6 1 1 3 3 1 1 1 1 1 1 1 1 1 1 1 6 3 3 1 1 1 1 1 1 end label values occubefore occubefore label def occubefore 1 "Agriculture", modify label def occubefore 2 "Business", modify label def occubefore 3 "Government service", modify label def occubefore 4 "Private employee", modify label def occubefore 5 "Daily wage labourer", modify label def occubefore 6 "Others", modify label values occuafter occuafter label def occuafter 1 "Agriculture", modify label def occuafter 2 "Business", modify label def occuafter 3 "Government service", modify label def occuafter 4 "Private employee", modify label def occuafter 5 "Daily wage labourer", modify label def occuafter 6 "Others", modify
Comment