Learning Objectives

Following this assignment students should be able to:

  • Run simple and multivariate regressions in Stata
  • Interpret regression coefficients, standard errors, and p-values
  • Use factor variables, interactions, and polynomials
  • Choose appropriate standard error corrections (robust, clustered)
  • Diagnose collinearity using VIF

Reading

Topics

  • Single variable regressions
  • Multivariate regressions
  • Correcting standard errors
  • Weights
  • Collinearity
  • Measurement error

Readings

Lecture Notes

  1. Single and Multivariate Regression
  2. Standard Errors
  3. Weights, Collinearity, and Measurement Error

Exercises

  1. Simple Regression (10 pts)

    For all the exercises this week we are going to use eth_allrounds_final.dta. Before we start, after loading the data:

    • Drop all observations that are not maize
    • Generate a variable called fert that measures nitrogen fertilizer in kg per hectare (nitrogen_kg / plot_area_GPS). Label the variable.
    • Generate a variable called labor that measures total labor in days per hectare (total_labor_days / plot_area_GPS). Label the variable.

    This maize only data set with per hectare inputs will be the one we use for all the exercises this week. It will make our yield function regressions more realistic.

    1. Create a scatter plot of yield_kg against fert with a fitted line (lfit)
    2. Run reg yield_kg fert
      • What is the slope on fert and how do you interpret it?
      • Is it statistically significant at the 5% level?
      • What is the R-squared and what does it mean?

  2. Multivariate Regression (10 pts)

    Using the maize only version of eth_allrounds_final.dta with per hectare inputs, run a multivariate regression: reg yield_kg fert labor i.irr

    1. How did the coefficient on fert change compared to the simple regression?
    2. Interpret the new coefficient on fert using the phrase “holding fixed.”
    3. What is the coefficient on 1.irr? Explain it as a difference in averages.

  3. Factor Variables and Interactions (10 pts)

    Using the maize only version of eth_allrounds_final.dta with per hectare inputs:

    1. Run a regression of yield_kg on fert and labor, adding regional fixed effects with i.admin_1. Which region is the omitted reference category?
    2. Run a regression with an interaction between fertilizer (c.fert) and irrigation (i.irr). What is the coefficient on the interaction term? What does the interaction coefficient mean?
    3. Fit a quadratic in fertilizer. What does the sign of the squared term tell you about diminishing returns?

  4. Predicting Values (10 pts)

    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 yhat to generate predicted values
    • Use summ yield_kg yhat, meanonly to find the plotting range
    • Save the minimum and maximum values for yhat AND yield_kgas locals, for example:
    	qui sum			yhat, meanonly
    	local			yhat_min = r(min)
    	local			yhat_max = r(max)
    
    • Create locals called gmin and gmax that are the minimum and maximum of yhat and yield_kg. For example, gmin = min(yhat_min’, yield_min')
    • Use twoway scatter to create the scatter plot
    • Add the 45° reference line with function y = x and use the locals in the range option function y = x, range(gmin' gmax')

  5. Residual Plots (10 pts)

    Using the maize only version of eth_allrounds_final.dta with per hectare inputs:

    1. Make a residual-vs-fitted plot and check for heteroskedasticity

    • Run reg yield_kg fert labor i.irr i.admin_1.
    • Use predict yhat to generate predicted values.
    • Use predict resid, residuals to generate residuals.
    • Use twoway scatter to create a scatter plot of resid against yhat with a horizontal line at zero (yline(0)).

    2. Does the vertical spread of residuals change across the x-axis? What does this suggest about heteroskedasticity?


  6. Robust Standard Errors (10 pts)

    Using the maize only version of eth_allrounds_final.dta with per hectare inputs, compare default and robust standard errors.

    • Run reg yield_kg fert labor i.irr i.admin_1 (default standard errors).
    • Run the same regression with , robust appended.
    1. Did the coefficients change?
    2. How did the standard error on fert change?
    3. Did the p-value on fert change in a way that would affect your conclusions?

  7. Clustered Standard Errors (10 pts)

    Using the maize only version of eth_allrounds_final.dta with per hectare inputs, compare default and clustered standard errors.

    • Run reg yield_kg fert labor i.irr i.admin_1, robust
    • Run the same regression with clustered standard errors: , vce(cluster hhid)
    1. How did the standard error on fert change when moving from robust to clustered?
    2. Does clustering at the household level or plot-level make sense for this data?

  8. Collinearity and VIF (10 pts)

    Using the maize only version of eth_allrounds_final.dta with per hectare inputs, diagnose collinearity with the Variance Inflation Factor.

    • Run reg yield_kg fert labor i.irr i.admin_1 seed_value_LCU seed_value_USD
    • Run estat vif immediately after the regression
    1. Which variables have VIF values above 5? Above 10?
    2. Why might the seed variables be collinear?
    3. If VIF is high, does that mean the coefficients are biased, or just imprecise?

  9. Check That Your Code Runs (10 pts)

    Sometimes you think you’re code runs, but it only actually works because of something else you did previously. To make sure it actually runs you should save your work and then run it in a clean environment.

    Follow these steps in to make sure your code really runs:

    1. Restart Stata by closing the instance of Stata that you have open.

    2. When you reopen Stata, type in the command line clear all. Or, better yet, put clear all at the top of your .do file, after the preamble but before any commands.

    3. Rerun your entire homework assignment by clicking the Execute button to make sure it runs from start to finish and produces the expected results.

    4. Make sure that you saved your code with the name of the assignment number (i.e., assignment_01). You should see the file in your git repo on your machine.

    5. Make sure that your code will run on other computers (relevant for all assignments after the first assignment)

      • No cd. Use a project.do file instead to set directories
      • Use only relative paths in files other than the project.do file
      • Use / not \ for paths

  10. Challenge 9 (Challenge - 20 pts)

    This challenge uses the maize only version of eth_allrounds_final.dta with per hectare inputs to practice skills from all three regression lectures (regression, standard errors, concerns).

    • Start by creating a variable called seed that measures the total seed value for each plot in USD per hectare
    • Now run a multivariate regression of yield_kg on fert, labor, seed, i.irr, i.intercropped, i.crop_shock, i.admin_1, and i.wave

    1. Interpret the coefficient on labor using the phrase “holding fixed”

    2. Run estat vif. Which variables, if any, have VIF values above 5? Explain whether collinearity is a concern in this specification

    3. Use predict yhat and predict resid, residuals to generate predicted values and residuals

    • Create a scatter plot of resid against yhat with yline(0)
    • Is there evidence of heteroskedasticity?

    4. Run the same regression three ways (normal s.e., robust s.e., and s.e. clustered at household)

    • What are the standard errors on fert each time?
    • Which approach is most appropriate for these data and why?

    5. Run a regression with an interaction between fert and labor. How do you interpret the coefficient on fert, labor, and c.fert##c.labor?

Assignment submission checklist

Solutions

  1. Simple Regression 1, 2
  2. Multivariate Regression
  3. Factor Variables and Interactions
  4. Predicting Values
  5. Residual Plots 1, 2
  6. Robust Standard Errors
  7. Clustered Standard Errors
  8. Collinearity and VIF
  9. Check That Your Code Runs
  10. Challenge 8 1, 2