I am using -reghdfe- command with the , residuals() option. After the estimation is outputted, I predict the outcome variable with -predict , xbd-
Somehow, when I plot the predicted values against the residuals I see a strong negative relationship. I am not sure why as, by construction, we should expect predicted values to be uncorrelated with regression residuals. I am not sure what I am missing.
Below is a random sample of data. My outcome (y) is a measure between 0 and 1. The independent variables (x1-x11) are either shares, categorical, or continuous variables.
My code is
Below is the output of the scatterplot for the sampled data. Because the sample is quite small (100obs), visual interpretation is not very straightforward. For this reason, also copied bellow the plot that comes out when I use my entire data (15M obs).
Although I can see a clear negative relationship - which for me seems (very) linear. However, when I add the linear prediction (with command -lfit-), it outputs a flat line. I am very puzzled - isn't there a negative correlation? Is this some higher order relationship? Is it because my dependent variable is a share?
Somehow, when I plot the predicted values against the residuals I see a strong negative relationship. I am not sure why as, by construction, we should expect predicted values to be uncorrelated with regression residuals. I am not sure what I am missing.
Below is a random sample of data. My outcome (y) is a measure between 0 and 1. The independent variables (x1-x11) are either shares, categorical, or continuous variables.
Code:
clear input byte x10 int x11 byte(x9 x7 x6 x5 x8) float(x1 x2 x3 x4 y) 1 1 1 0 0 0 54 .5263158 0 51.78947 .8947368 .5882353 0 9 1 1 1 0 59 .6315789 .8421053 46.52632 .6315789 .15 0 50 1 0 1 0 48 1 .3333333 36.666668 .3333333 .08695652 0 51 0 0 0 0 29 0 0 60 0 1 0 17 0 1 1 1 55 .72 .76 50.2 .16 .5720078 1 22 0 0 0 0 74 .5833333 .4166667 43.75 .3333333 0 1 21 1 0 1 1 44 .8695652 .4583333 40.91667 .4166667 .25576082 0 30 0 0 1 1 33 .6944444 .8611111 44.44444 .1388889 .28941944 1 0 1 0 0 0 43 .6521739 .2173913 41.13044 .7391304 .50441176 0 41 0 0 0 0 75 .8 .2631579 46 .1 .1608839 1 23 0 0 1 1 33 .4 0 43.5 .4 .20363636 0 57 0 1 1 1 31 .8 .2 38.6 .6 .08099548 1 36 0 1 1 1 56 .8461539 .4230769 44.42308 .53846157 .27968207 0 62 1 0 1 1 33 .05882353 .26666668 47.58823 .1764706 .12831196 0 71 0 0 1 1 36 .6 .1 33 .5 .22727273 0 57 1 0 0 0 41 .6071429 .26666668 33.966667 .4666667 .3782748 0 12 0 0 0 0 62 0 0 28 0 .1818182 1 32 1 0 0 0 41 .54285717 .4 45.08823 .25714287 .25668496 1 0 1 0 0 0 50 .4878049 .4285714 48.52381 .6904762 .2142857 1 20 1 0 1 1 67 .625 .032258064 40.28125 .75 1 0 9 0 1 1 1 40 .8484849 .24242425 35.47059 .029411765 .3019737 1 44 0 1 1 1 57 .5 .4 45.8 0 .50032127 1 19 1 0 1 0 59 .680851 .14432989 43.47959 .29591838 .02603046 1 17 0 1 0 0 64 .2142857 .4285714 40.85714 .2142857 .5 1 36 0 0 0 0 36 .9318182 .022727273 33.727272 .27272728 .50244087 0 57 1 1 0 0 42 .2857143 .2142857 53.2 .4 .6139038 0 1 1 0 1 0 25 .4722222 .17714286 37.67442 .4659091 .467557 1 32 0 1 1 1 55 .625 .125 49.375 .625 0 1 38 0 0 0 0 40 .3787879 .2153846 44.72308 .1846154 .56609195 1 3 0 0 0 0 76 .16666667 0 53.5 .16666667 0 1 68 0 0 1 1 33 .9285714 .071428575 41.92857 .6428571 .09444445 0 13 0 0 1 1 40 1 0 40.14286 0 .1568661 1 30 0 0 0 0 77 .5 .16666667 49 .3333333 0 1 59 0 0 1 1 42 .3571429 0 46.85714 .4285714 .3333333 1 19 1 0 0 0 36 .6551724 .3103448 40.68966 .7241379 0 1 33 1 0 1 1 31 .5555556 .3333333 38.33333 .3333333 0 1 28 1 1 1 1 32 .6304348 .5217391 32.565216 .7826087 .3465563 1 0 1 1 0 0 38 .5555556 .029411765 39.74286 .7142857 .52568924 1 23 0 0 0 0 50 .5217391 .6304348 43.13044 .26086956 .07692308 1 28 1 0 1 1 30 .8461539 0 37.346153 .5769231 .334188 1 0 0 0 0 0 46 .75 0 43.625 .625 1 1 57 0 0 1 1 42 .3333333 0 53 0 .4334689 1 36 1 0 1 1 50 .5714286 .0882353 47.26471 .5588235 .6126241 0 80 0 0 0 0 46 .44871795 .006451613 42.55484 .3612903 .15776224 1 16 1 0 1 1 36 .6818182 .13636364 37.454544 .8181818 .26440966 1 72 0 0 1 0 26 .3538462 .22222222 43.74603 .26984128 .6 0 62 0 0 0 0 45 .29411766 .0625 49.05882 .29411766 .3614719 0 2 0 1 1 1 40 .625 .4285714 47.25 .25 .68 1 34 0 0 1 1 60 .7692308 0 47.19231 .03846154 .2602126 1 21 0 1 1 1 40 .7105263 .6216216 34.027027 .6486486 .1746231 1 75 1 0 1 1 32 .6785714 .2413793 39.62069 .1724138 .073525034 0 0 1 0 0 0 46 .5714286 0 52 1 .4375 1 18 1 0 1 0 28 .57894737 .1794872 38.82051 .6153846 .3151182 1 51 0 1 1 1 37 .8695652 .7555556 36.2 .7333333 .07427717 0 64 0 0 0 0 67 .7222222 .23076923 47.51282 .15384616 .16756584 1 24 1 1 0 0 49 .4583333 .5 45.625 .25 .030253837 0 39 0 0 0 0 36 .875 .14285715 36.625 .375 .27646592 1 83 0 0 0 0 56 .5882353 .1764706 50.35294 .05882353 .072463766 1 20 1 0 1 1 37 .3050847 .2142857 48.87719 .46551725 .4525482 0 57 0 0 1 1 36 .7058824 .2352941 36.38889 .22222222 .6969348 1 0 1 0 1 1 37 .3 .25 46.25 .55 .6430992 0 66 1 0 0 0 45 .3230769 .22222222 46.65625 .25 .3028898 0 45 1 0 1 1 31 .3043478 0 49.04348 .4347826 .18554625 1 25 1 0 1 0 25 .3333333 .1632653 35.408165 .6326531 .26354167 1 44 1 0 0 0 35 .2857143 .071428575 48.14286 .4642857 .2323292 0 92 0 1 1 1 56 .6351351 .8943662 48.3169 .14788732 .29436913 1 2 1 1 1 1 41 .7142857 .8571429 43.97143 .7428572 .4666667 1 39 1 0 0 0 47 .7 .26666668 44.48276 .53333336 .3899566 1 35 0 0 0 0 38 .7162162 .02702703 33.905407 .2837838 .3087257 1 86 0 0 0 0 68 .6666667 .6666667 43.33333 0 0 1 32 1 1 1 1 29 .9333333 .8666667 35.866665 .4666667 .4693878 1 58 0 1 1 0 36 .6883117 .8552632 37.05263 .27631578 0 1 2 0 1 0 0 51 .6666667 .6666667 44.41667 .08333334 .23710424 1 0 0 0 1 0 29 0 0 50.2 .4 .7777778 0 55 1 0 0 0 47 .125 .06666667 44.57143 .26666668 .6597222 1 24 0 0 0 0 58 0 0 53.2 .4 0 0 84 1 0 1 1 41 .8163266 .16 45.78 .12 .2039952 0 21 0 0 0 0 36 .4285714 .071428575 37.357143 .7857143 .4722222 0 52 0 1 1 1 36 .6363636 .6521739 42.17391 .04347826 .07777778 1 43 0 0 0 0 67 .125 .625 58.375 .125 0 1 31 1 0 1 1 41 .8448276 .1754386 43.54237 .4237288 .05888571 0 50 0 1 1 0 27 .58536583 .3373494 48.3253 .19277108 .3475826 0 26 0 1 0 0 43 .64 .25 39 0 .2777778 1 80 0 0 1 1 47 1 0 43 0 0 0 52 0 0 1 1 31 .3148148 .16666667 43.05556 .14814815 .3966942 0 47 1 1 0 0 27 .4615385 .3076923 48.23077 0 .08333334 0 1 0 0 1 1 55 .425 .3809524 52.92857 .16666667 .3464052 0 52 0 0 1 1 31 .7352941 .04477612 36.41791 .1641791 .4180558 0 43 0 0 1 1 27 .6842105 .2777778 34.864864 .4054054 .4328156 1 81 1 1 0 0 37 .08333334 .4166667 54.08333 .08333334 .3333333 0 31 0 0 1 1 46 .7333333 .27586207 39.2 .033333335 .3650794 0 63 0 0 1 1 47 .7368421 .15789473 40.89474 .15789473 .4089053 1 0 0 1 1 1 50 .22222222 .3333333 56.88889 .5555556 .27586207 0 62 1 1 1 1 33 .6506024 .58536583 42.78049 .2195122 .20441154 0 65 0 0 1 1 45 .47887325 .11764706 36.766422 .3956835 .3669803 1 25 1 0 1 1 37 .9473684 0 38.84211 .8947368 .4285714 1 84 1 0 0 0 47 .6229508 .11111111 40.88525 .296875 .4164711 0 59 0 0 1 1 30 .6285715 .34285715 43.37143 .2857143 .6478174 1 77 0 1 1 1 35 .6521739 .26086956 40.95652 0 .4347826 0 53 0 0 0 0 67 .08333334 0 36.416668 .25 .5 end
Code:
reghdfe y x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11, residuals(RES) predict Y_HAT, xbd scatter Y_HAT RES
Although I can see a clear negative relationship - which for me seems (very) linear. However, when I add the linear prediction (with command -lfit-), it outputs a flat line. I am very puzzled - isn't there a negative correlation? Is this some higher order relationship? Is it because my dependent variable is a share?