Predicting Values (Regression)
Using the maize only version of eth_allrounds_final.dta with per hectare inputs compute and graph predicted values from a regression.
- Run
reg yield_kg fert labor i.irr i.admin_1 - Use
predict yhatto generate predicted values - Use
summ yield_kg yhat, meanonlyto find the plotting range - Save the minimum and maximum values for
yhatANDyield_kgas locals, for example:
qui sum yhat, meanonly
local yhat_min = r(min)
local yhat_max = r(max)
- Create locals called
gminandgmaxthat are the minimum and maximum ofyhatandyield_kg. For example,gmin = min(yhat_min’,yield_min') - Use
twoway scatterto create the scatter plot - Add the 45° reference line with
function y = xand use the locals in the range optionfunction y = x, range(gmin'gmax')