Announcement

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

  • how to add a quadratic fit with sepscatter command

    Hello everyone,

    I would like to add a quadratic fit to a scatter plot that have different circles colors by a specific categorical variable. I found the sepscatter command very helpful to generate this type of scatter, but it does not accept the "twoway qfitci" command.

    Actually, I know that we can do that using the "twoway qfitci" command and adding a scatter plot to each category of the variable of interest using the "|| scatter" option. But the problem is that I am weighting the scatter by a certain variable, and it seems that adding multiple scatters makes circles' size comparable only within each category of the variable not between categories. This is why I would like to use sepscatter command. I would highly appreciate your help.

    I am giving an example here with the auto dataset

    Code:
    sysuse auto, clear
    Code:
    sepscatter price weight , separate( foreign ) msymbol(oh oh) ytitle("price") xtitle("weight") legend(off)

  • #2
    sepscatter is from SSC (FAQ Advice #12).

    I can't see a way to make that work. In essence, qfitci needs access to two (or in other examples more) separate variables that don't exist when the call is made. Supporting that is programmable at the expense of complicating the code and documentation considerably.

    Best to do it directly.

    Code:
    sysuse auto, clear 
    separate price, by(foreign) veryshortlabel
    set scheme s1color 
    twoway qfitci price0 weight, color(red*0.1) clcolor(red) || qfitci price1 weight, color(blue*0.1) clcolor(blue) || scatter price? weight, ms(Oh X) mc(red blue) legend(order(6 5) ring(0) pos(11)) ytitle(Price (USD))

    Comment


    • #3
      Thanks a lot Nick Cox for your time and help. I would ask, Is there any way to have only one quadratic fit for the whole data while using the scatter command with different color-coding instead of two for each category?. I am attaching a similar graph of what I created using the || scatter option. But again weights are used, circles' size becomes comparable only within each group.
      Click image for larger version

Name:	scatter.png
Views:	1
Size:	33.5 KB
ID:	1700438


      Last edited by Mona Elsayed; 05 Feb 2023, 10:12.

      Comment


      • #4
        Sorry, but I don't understand the new question. You don't show anything to do with weights.

        Comment


        • #5
          Unfortunately, the data itself is confidential and the auto dataset does not have a weighting variable. I mean if I use the weights with "twoway qfitci .... || scatter", I will end up with a graph in which circles' size could be compared only within each group not between groups.
          Here is another example of the graph from a published paper. I need to create a similar graph but I want circles' size to be comparable for the whole data not per each group.
          Click image for larger version

Name:	scatter.png
Views:	1
Size:	75.8 KB
ID:	1700442

          Comment


          • #6
            You're adding to my prejudice that such graphs combining points, weights and a fit with confidence intervals are just too messy to be worth producing. That graph seems to be undermining itself with so many big circles lying outside the shaded zone.

            However, the point is how to get what you want in Stata without the problem you report. I dimly record a work-around for this but I can't remember what it is. Someone else may be able to help.

            Comment


            • #7
              Actually resizing the circles for each category contributes further to this noise, this is why I am trying to avoid. Thank you Nick!

              Comment

              Working...
              X