Take-home final

EC 421: Introduction to Econometrics

Author

Edward Rubin

1 Important

What follows below is a new exam that I wrote this week. After writing the exam, I asked ChatGPT to answer each question. Below you will find the prompts and ChatGPT’s answers.

Your job is to complete each prompt and then evaluate whether ChatGPT was correct or incorrect. Sometimes ChatGPT is correct; sometimes it is not.

What you submit:

  • If ChatGPT is correct, explain why the answer is correct.
  • If ChatGPT is incorrect, explain why it is incorrect and provide the correct answer.
  • If the prompt requested an analysis in R, you need to include your R code and the output of the analysis.

2 Setup and data

Source Imagine you work for a large tech company that sells stuff to consumers via a website. The company wants to make more money, as companies often do. A new company executive has noticed that when people visit a specific product’s website, they tend to spend more money. You’ve been assigned the job of quantifying how much extra money people spend, on average, if they visit the product’s website.

Definition The data represent a hypothetical experiment where you randomly gave out coupons (coupon) to 1,000 visitors to the main website. You then tracked whether or not the visitors visited the product website (visit). Finally, you observe the amount each person purchased. I generated the data for this exam.

Note: Because the website is so popular, you actually observed each individual twice during the experiment (hence the 2,000 observations for 1,000 individuals).

And here are the descriptions of the variables in the dataset.

Variable names and descriptions
Variable name Variable description
i Observation number
ind Individual number (stays the same within an individual visitor)
coupon Binary indicator: Whether the visitor received a coupon
visit Binary indicator: Whether the visitor visited the product’s page
purchase Number: Total purchase amount (in dollars)

3 Academic honesty

You are not allowed to work with anyone else. Working with anyone else will be considered cheating. You will receive a zero for both parts of the exam and may fail the class.

You can use online materials, books, notes, solutions, etc. However, you still must put all of your answers in your own words. Copying other people’s words will be considered cheating.

Shan and Ed will not help you debug your code. Do not ask.

4 General instructions

Data You will need the data contained in final-data.csv.

Points There are 40 points available on this portion of the midterm. The in-class portion of the midterm is worth 120 points. Your total final-exam grade will be the sum of the points you earned on the two parts divided by 160 (= 120 + 40).

Due Upload your answers on Canvas before 11:59 pm (Pacific) on Thursday, 23 March 2023.

Important You must submit two files:

  1. your typed responses/answers to the question (in a Word file or something similar)
  2. the R script you used to generate your answers. Each student must turn in her/his own answers.

If you are using RMarkdown (or Quarto), you can turn a single file, but it must be a html or pdf file with both your R code and your answers.

All figures and regression output (tables) should be visible in the file you submit for your writeup. You will not get credit for just the code. We will not run your code. If we ask you to create a figure or run a regression, then the figure or the regression results should be in the document that you submit (not just the code—we want the actual figure or regression output with coefficients, standard errors, etc.).

Do not write your answers in the comments of your R script file. You will not receive credit for answers written in the R script. Do not submit an RMD file as your answer either—you will not receive points.

5 Prompts

[01] (5 points) Before you ran the experiment, your hypothetical company executive (referenced above) suggested that you could regress the total amount purchased on an indicator for whether the visitor visited this “product website” (visit). Explain why this comparison likely suffers from selection bias.

Hint: Recall (see above) that the goal is to estimate the causal effect of getting a visitor to visit the product page.

ChatGPT:

The suggested approach of regressing the total amount purchased on the indicator for whether the visitor visited the product website (visit) likely suffers from selection bias because it does not take into account the possibility of confounding factors. In other words, it assumes that the only difference between those who visit the product website and those who do not is the visit itself.

However, there might be other factors influencing both the decision to visit the product website and the total amount purchased. For example, visitors who are more interested in the product, or who have a higher propensity to spend, might be more likely to visit the product website. In this case, the observed relationship between visit and the total amount purchased would not necessarily reflect the causal effect of visiting the product page. Instead, it would be capturing the effect of these unobserved factors as well.

By simply comparing the purchase amounts between the two groups (those who visited and those who did not visit the product website), we would not be able to isolate the causal effect of visiting the product page. This is why the comparison suffers from selection bias, and a more robust approach, like a randomized controlled trial, would be necessary to estimate the true causal effect.

Answer ChatGPT gets the answer correct here. If you regress purchase on an indicator for “visited the product website”, we would be comparing the average purchase for visitors to the average purchase for non-visitors. To get the causal effect of visiting the product website, we would need visitors and non-visitors to only differ in having visited the website. However, these two groups could differ in many important ways that would cause the purchase amounts to differ. Thus, the comparison (and related regression) would likely suffer from selection bias.

[02] (5 points) Do you expect the selection bias in the suggested analysis in [01] to cause us to overestimate or underestimate the actual effect of visiting the product page? Explain your answer.

ChatGPT:

The selection bias in the suggested analysis in [01] is likely to cause us to overestimate the actual effect of visiting the product page. Here’s why:

As mentioned earlier, there might be confounding factors that influence both the decision to visit the product website and the total amount purchased. One such factor could be the individual’s interest in the product or their propensity to spend.

Visitors with a higher interest in the product or a higher propensity to spend are more likely to visit the product page. These visitors are also likely to spend more, regardless of whether they visit the product page or not. If we don’t account for these factors, the regression analysis would attribute the higher spending to the act of visiting the product page, when in reality, it might be due to the individual’s inherent interest or spending propensity.

This would lead to an overestimation of the actual effect of visiting the product page, as the observed relationship between visit and the total amount purchased would be capturing not only the causal effect of visiting the product page but also the effect of the unobserved confounding factors.

Answer ChatGPT gives a solid answer here.

We can sign the bias either using our omitted-variable bias formula or by thinking about the definition of selection-bias. With the selection-bias formula, we compare the average untreated outcome for the treated group to the average untreated outcome for the control group:

\[\text{Avg}(Y_{0i} | D_i = 1) - \text{Avg}(Y_{0i} | D_i = 0)\]

If, as ChatGPT suggests, individuals who visit the product page are just more affluent or more interested in other products on the website, then the selection bias here is going to be positive—causing us to overestimate the true effect.

It is also possible that the selection bias is negative (causing us to underestimate the effect). That situation would require that people who visited the website were going to spend less money than people who did not visit the website (had they not visited the website).

[03] (5 points) The experiment randomly offered visitors a five-dollar coupon on the company’s main page. Explain how this randomization helps us to use the coupon variable as a valid instrument for the visit variable.

ChatGPT:

Using the coupon variable as an instrument for the visit variable can help address the issue of selection bias and estimate the causal effect of visiting the product page on the total amount purchased. Randomly offering visitors a five-dollar coupon on the company’s main page ensures that the coupon distribution is independent of any confounding factors that may be associated with the decision to visit the product website and the total amount purchased.

The randomization of the coupon distribution satisfies the two key assumptions of a valid instrumental variable:

  1. Relevance: The instrument (coupon) should be correlated with the endogenous variable of interest (visit). In this case, receiving a coupon is likely to influence the visitor’s decision to visit the product page, as they may be more inclined to explore the product and potentially make a purchase due to the discount.

  2. Exogeneity: The instrument (coupon) should not be correlated with the error term in the outcome equation, which implies that it should not be directly related to the unobserved factors that affect the total amount purchased. Since the coupons are randomly distributed, they are not systematically related to the visitors’ inherent interest in the product, propensity to spend, or any other confounding factors.

By using the coupon variable as an instrument for the visit variable, we can address the selection bias issue and obtain a more accurate estimate of the causal effect of visiting the product page on the total amount purchased. The randomization of the coupon distribution helps ensure that the relationship between the instrument (coupon) and the outcome (total amount purchased) is only through its influence on the endogenous variable of interest (visit), allowing for a more robust causal analysis.

Answer ChatGPT gives a solid answer here.

By randomizing the coupon, we likely meet the exogenous requirement for the instrument.

We cannot be sure (yet), but if the random coupon increases the likelihood that individuals visit the website, then the coupon instrument is also relevant.

[04] (5 points) Run the first-stage regression, where our outcome of interest is the total purchase (purchase), our variable of interest is whether the visitor visited the product’s website (visit), and coupon is our instrumental variable. Report your results and interpret both the intercept and the coefficient.

ChatGPT:

As an AI language model, I am unable to directly run statistical software or regressions. However, I can guide you through the process of running the first-stage regression and help you interpret the results.

To run the first-stage regression, you would use a statistical software or programming language such as R, Python, or Stata to perform the following steps:

  1. Load your dataset into the software.
  2. Perform the first-stage regression with the visit variable as the dependent variable and the coupon variable as the independent variable (instrument). The regression equation would look like this:

visit = α + β * coupon + ε

After running the regression, you should obtain the results, which include the intercept (α) and the coefficient for the coupon variable (β).

Interpretation of the intercept (α): The intercept represents the predicted probability of visiting the product’s website when the visitor does not receive a coupon. In other words, it is the baseline likelihood of a visitor visiting the product page without any intervention.

Interpretation of the coefficient for the coupon variable (β): The coefficient for the coupon variable represents the change in the probability of visiting the product’s website when a visitor receives a coupon compared to when they do not receive a coupon. A positive coefficient would indicate that receiving a coupon increases the likelihood of visiting the product page, while a negative coefficient would indicate a decrease in the likelihood.

Answer Aside from not being able evaluate its R code, ChatGPT does a great job with this answer.

# Load packages
library(pacman)
p_load(tidyverse, estimatr, fixest)
# Load the dataset
final_df = 'final-data.csv' |> read_csv()
Rows: 2000 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (5): i, ind, coupon, visit, purchase

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Run the first stage
reg_stage1 = feols(visit ~ coupon, data = final_df)
# A table
reg_stage1 |> etable()
                        reg_stage1
Dependent Var.:              visit
                                  
Constant        0.5098*** (0.0158)
coupon          0.1226*** (0.0220)
_______________ __________________
S.E. type                      IID
Observations                 2,000
R2                         0.01534
Adj. R2                    0.01485
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Interpretation:

  • The intercept tells us that without receiving a coupon, there was a 50.98 percent probability that an individual would visit the product page.
  • The coefficient tells us that, on average, the coupon increased the probability of visiting the product page by 12.26 percentage points.

[05] (5 points) Using the first-stage results in [04], explain whether coupon appears to be a valid instrument.

ChatGPT:

In order to determine if coupon appears to be a valid instrument, you should assess the two key assumptions of a valid instrumental variable based on the first-stage regression results mentioned in [04]:

  1. Relevance: To determine if the coupon variable is relevant, you should look at the coefficient (β) of the coupon variable in the first-stage regression. A statistically significant and non-zero coefficient would indicate that the coupon variable is correlated with the endogenous variable of interest, visit. This would mean that receiving a coupon influences a visitor’s decision to visit the product page, satisfying the relevance assumption.
  2. Exogeneity: Although the first-stage regression results cannot directly confirm the exogeneity assumption, you can rely on the experimental design to assess this assumption. Since the coupons were randomly distributed to visitors, the coupon variable should not be systematically related to any unobserved factors that affect the total amount purchased. This would satisfy the exogeneity assumption.

If both the relevance and exogeneity assumptions are met based on the first-stage regression results and experimental design, then coupon appears to be a valid instrument for the visit variable. This would allow you to proceed with the second-stage regression to estimate the causal effect of visiting the product page on the total purchase amount, accounting for potential selection bias.

Answer ChatGPT’s answer is too long for my taste. What it says is technically correct, but it provides too much information.

The only requirement that we can use the first stage regression to tell us about is the relevance. Because the coefficient on coupon is highly statistically significant, we have evidence that the instrument is indeed relevant.

[06] (10 points) Estimate the parameter of interest (the effect of visiting the product’s website on total purchase) using two different regression approaches:

  1. Ordinary least squares
  2. Instrumental variables

Report your results and discuss whether the difference in the estimates is consistent with your hypothesized direction of selection bias in [02].

ChatGPT:

The difference in estimates between the OLS and instrumental variables regressions is that the latter is larger than the former. This is consistent with our hypothesized direction of selection bias, which was that visitors who visit the product’s website tend to spend more money, so those who actually visit the website are likely to be a more motivated and higher-spending group. By using the instrumental variables approach, which accounts for the potential endogeneity of visit, we are able to obtain a more unbiased estimate of the effect of visiting the product’s website on total purchase.

Answer ChatGPT’s answer is not quite right here. It is correct that we did hypothesize that there would be positive selection bias. However, such selection bias would mean the OLS estimates should be larger than the instrument-variables estimates, as we find below. In other words, the bias is indeed consistent with our hypothesized selection bias; ChatGPT just made a mistake.

# The OLS regression
reg_ols = feols(purchase ~ visit, data = final_df)
# The IV regression
reg_iv = feols(purchase ~ 1 | 0 | visit ~ coupon, data = final_df)
# The table
etable(reg_ols, reg_iv)
                          reg_ols           reg_iv
Dependent Var.:          purchase         purchase
                                                  
Constant        82.27*** (0.5446) 92.59*** (3.837)
visit           63.10*** (0.7195) 45.09*** (6.658)
_______________ _________________ ________________
S.E. type                     IID              IID
Observations                2,000            2,000
R2                        0.79381          0.72914
Adj. R2                   0.79370          0.72900
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

[07] (5 points) Estimate the reduced-form regression and use the estimates to discuss whether the $5 coupon appears to be profitable.

ChatGPT:

Based on this calculation, it appears that the $5 coupon is profitable, as the expected profit from the coupon is positive. However, we should note that this calculation assumes that the only effect of the coupon is to increase the likelihood of visiting the product page. If the coupon also affects the amount of money spent, then this calculation would not be accurate.

Answer ChatGPT does not do a very good job here. I think it’s confused what the reduced form will tell us: it’s going to tell us the change in spending due to receiving a coupon (not the change in the likelihood of a visit).

Let’s run the reduced form.

# The reduced-form regression
reg_rf = feols(purchase ~ coupon, data = final_df)
# The table
reg_rf |> etable()
                          reg_rf
Dependent Var.:         purchase
                                
Constant        115.6*** (1.122)
coupon          5.528*** (1.563)
_______________ ________________
S.E. type                    IID
Observations               2,000
R2                       0.00622
Adj. R2                  0.00572
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

First, we were not entirely clear on whether every “coupon visitor” just received $5 or if they only got $5 when they made a purchase on the product page.

Either way: The reduced-form results show us that, on average, individuals who received the $5 coupon spent $5.53 more than individuals who did not. So even if we lose $5 every time we give out a coupon, we are still making a profit (on average).

That said, the standard error on coupon in the reduced form is fairly large, so we cannot say whether we are significantly above five dollars. So we cannot say for sure that this experiment is profitable.