Seaborn’s regplot and Stata’s binscatter disagree`

  Kiến thức lập trình

I’m running on the same data either binscatter2 from STATA, or seaborn’s regplot — as below.

Both these claim in their documentations that they first bin data based on the x-values into 20 equal sized groups, and then plot in the scatter plot the y-mean for each group.
My code below (difficult to replicate since one needs the STATA package for python and Stata 18 installed) attempts to compare the outcome for both packages.

Below are first the seaborn figure, and then the stata figure. As you can see, the OLS regression line agrees (roughly), but the points — neither the x-location nor the y-location — do. What am I missing?

    import seaborn as sns
    from pystata import stata
    stata.pdataframe_to_data(df, force=True)
    stata.run('binscatter2 y_var x_var, nquantiles(20)')
    sns.regplot(df, x='x_var', y='y_var', x_bins=20, truncate = True)

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT