leojahrens / scatterfit

scatterfit Stata ado to create scatter plots with fit lines
31 stars 7 forks source link

Legend Options #2

Closed apkaye closed 1 year ago

apkaye commented 1 year ago

Hi - this package is really nice!

I've been trying it out and noticed that some of the legend options don't make it through to the plot. For example in the following code - the legend labels and position are not applied to the figure

    scatterfit ihs_booked_early OverallRating if OverallRating >=`mincut'-.5 & weekday==1, ///
      fit(polyci) ///
         bw(.1) ///
      by(star_group) ///
      binned nq(30) ///
      opts(${myxlines} ///
      ytitle("IHS(daily bookings)") ///
      xtitle("Overall Rating") ///
      legend(  lab(1 "2.5 Star") ///
                lab(2 "3  Star") ///)
              lab(3 "3.5 Star") ///)
              lab(4 "4  Star") ///)
              lab(5 "4.5  Star") ///)
              lab(6 "5  Star") ///
                col(1)  pos(6)))
Screenshot 2023-04-18 at 11 04 22 AM
leojahrens commented 1 year ago

Hi. Thanks! The legend labels are set based on the by-Variable (when by is specified). So the solution here is to correctly label the values of your by variable and then to execute the command. So in your case this should be lab def star_group 1 "2.5 Star" 2 "3 Star" 3 "3.5 Star" 4 "4 Star" 5 "4.5 Star" 6 "5 Star" lab val star_group star_group -> Then execute scatterfit

Regarding the legend position, I identified the problem in the code. The new version of scatterfit will fix it. I already wrote the code, but there are more updates and I will have to conduct extensive tests first to see if everything works as intended. I'll upload the update to GitHub by the end of the week. If you want to fix the problem yourself before then, go into the ado file and change the line local lscatteropts plotscheme'xtitle' ytitle'printcoef2' opts'legopts'

to: local lscatteropts plotscheme'xtitle' ytitle'printcoef2' legopts'opts'

Should be somewhere around line 600.

Let me know if there are further issues. Leo

leojahrens commented 1 year ago

Github outputs what I wrote about the line you should change in a weird way ... All the words after "local lscatteropts" refer to locals, so they should all be in these brackets `'

leojahrens commented 1 year ago

What is your plot about btw? Looks interesting

apkaye commented 1 year ago

Excellent, thank you! I'll try the labels and check back for the update.

This is still quite preliminary. The plot examines the connection between physicians' online reputation, measured by rounded half-star ratings, and their daily bookings. The platform rounds ratings to the nearest “half-star.” As a result, two physicians with nearly identical ratings can straddle one of the cutoffs, for example, to display 4.5 versus 5 stars. Consumers may view these physicians as very different, even if the underlying score is similar.

The figure is meant to document the booking gap at each cutoff. The vertical dotted lines mark the rounding cutoff for each half-star. The difference in the local polynomial estimate from the left vs right show us the booking gap.

leojahrens commented 1 year ago

The new version is up on GitHub. Please check if everything works now. Also check my Twitter thread for a summary of what's new.

https://twitter.com/leo__ahrens/status/1648998171870150660