I have a string variable (Reasons_Inadmissible) with multiple values that are comma separated. It lists all of the reasons why a case is inadmissible; multiple reasons can be listed in one cell. For example, one cell will read HRM, another will read HRM, LAW, another will read LAW, etc. Other values include REP, LON, OTE and others. I am trying to produce a frequency bar graph which indicates the number of cases where Reasons_Inadmissible is HRM, the number of cases where Reasons_Inadmissible is LAW, etc. In other words, I want a bar chart to indicate the number of cases that invoked a particular reason. Individual cases can be double-counted in this bar chart. I tried:
catplot Reasons_Inadmissible
But, it produces a bar chart with all possible combinations (i.e. HRM; HRM, LAW; HRM, OTE; LAW; OTE). Instead, I want the bars to represent the number of cases where one of the reasons was listed (just HRM, LAW, REP, OTE-- individually).
One options would be to generate a series of binary variables that are equal to 1 for each Reasons_Inadmissible value. For example:
gen HRC = 1 if strpos(Reasons_Inadmissible,"HRC")
gen LAW = 1 if strpos(Reasons_Inadmissible,"LAW")
However, in that case, how do I generate a bar graph, where the bars are counts of the different binary variables? Alternatively, is there another way you would recommend generating this graph from a comma-separated categorical variable?
Thanks!
Erica
Related Posts with Frequency bar graph for multiple binary variables
Cross sectional dependency in panel dataHello, I am working on a panel data of six Emerging economies with quarterly data from 2000-2020. S…
IV estimation (2SLS) with slope dummy variable interacting with endogenous variable.Hi, I want to estimate a regression with a dummy variable, say D. My dependent variable is Y. My exo…
loop for missing valuesHi everyone! I am trying to complete a database in form of a "tree", adding as values the last avail…
keep the last observation(s) in each yearDear All, Suppose that the data set is Code: * Example generated by -dataex-. To install: ssc insta…
Get name of specific variable which name is equal to another value of a variableI have a study where I am to look 28 days back in time before an event to see if the patients were w…
Subscribe to:
Post Comments (Atom)
0 Response to Frequency bar graph for multiple binary variables
Post a Comment