Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem producing a scatter graph with two independent variables and one dependent variable using bin scatter

    So I'm currently a student and started using Stata yesterday. I've been using the SSC command binscatter. Is there any way to plot two independent variables to compare them to each other using a dependent variable using the binscatter command? If I try to produce it using the normal scatter command the outputted graph is not easy to interpret, hence why I need to use the binscatter command. However, when using the binscatter command it returns that binscatter is not a twoway plot type. The dataset I am using is the British Social Attitudes Survey. What I am trying to measure is individuals' opinion when asked if they agree that differences in income are too large (incdiffsR1 in the following code). The response is measured from 1-5 along the y-axis (strongly agree - strongly disagree). So that is the dependent variable I am using. The independent variables I am using are income decile, measured from 1-10 along the x-axis (which is hhincdR1 in the following code) and perceived income decile, which is measured from 1-10 along the x-axis (which is socscaleR1 in the following code).

    Using the binscatter command for one dependent and one independent variable works completely fine like below
    Code:
    binscatter incdiffs hhincdR1


    when I try to do this with an additional variable like so

    Code:
    binscatter incdiffsR1 socscaleR1 hhincdR1
    The result is a graph with only one variable on the x-axis and two on the y-axis which is the opposite of what I want to happen

    When I try and create a twoway graph in the normal way like so

    Code:
    twoway (scatter incdiffsR1 hhincdR1) (scatter incdiffsR1 socscaleR1)
    The outputted graph is impossible to interpret so I need to use binscatter

    Code:
    twoway (binscatter incdiffsR1 hhincdR1) (binscatter incdiffsR1 socscaleR1)
    But then the output returns that "binscatter is not a twoway plot type"

    Any help on this would be greatly appreciated, thank you

  • #2
    Stata as usual is right. binscatter can't be used like that.


    As your x axis variables are already binned, the only question really is how to represent your y axis variable. A crude if contentious summary is the mean over answers 1 to 5, so

    Code:
    egen mean1 = mean(incdiffsR1), by(hhincdR1) 
    egen mean2 = mean(incdiffsR1), by(socscaleR1) 
    
    twoway connected  mean1 hhincdR1 , sort || connected mean2 socscaleR1, sort legend(order(1 "actual decile" 2 "perceived decile")) ytitle(Agree that too large) xtitle(Income deciles)
    Summaries that stick closer to the data are the fractions giving each answer, as in

    Code:
    egen frac5_1 = mean(incdiffsR1 == 5), by(hhincdR1) 
    egen frac5_2 = mean(incdiffsR1 == 5), by(socscaleR1)
    although in total that means 10 curves.


    Note. A new post in the same thread is better than a new thread on the same topic. I've posted a traffic diversion signal in your first thread.

    Comment


    • #3
      Thank you very much for that, that's exactly what I was looking for

      Comment

      Working...
      X