dataframestataanalysiscategorical-dataimpact-analysis

Plotting bar plots for categorical variables in STATA


I have a survey data baseline and endline. I am trying to plot bar plot for qualification of the respondent in each group (baseline/endline).

I am using the following code:

 graph bar, over(qualification) over(time)

It is giving me different output from what I want. my output I want the bars for endline and baseline for each category to be present parallel.

I am also attaching a reference picture to get the better idea about what I want.output which I want


Solution

  • The order of the over options of graph bar matters.

    Consider this example:

    clear
    input x str1 a b
    1 "a" 1
    2 "a" 2
    3 "b" 1
    4 "b" 2
    end
    
    graph bar x, over(a) over(b) title("over(a) over(b)")
    graph bar x, over(b) over(a) title("over(b) over(a)")
    

    example1 example2

    It looks like you need to swap the order of your over options.