remove_time_trends: Remove time trends

Description Usage Arguments Details

View source: R/residualize_outcome.R

Description

remove_time_trends removes seasonality from the data and detrends the data based on preferences provided by the user.

Usage

1
2
3
remove_time_trends(input_data, outcome_var, month_var, year_var,
  month_dummies = FALSE, calendar_time = FALSE,
  product_group_trend = FALSE, weight_var = NULL)

Arguments

input_data

The data containing the outcome and covariates (data.table).

outcome_var

The name of the outcome variable (character).

month_var

The name of the month variable (character).

year_var

The name of the year variable (character).

month_dummies

Residualize out month-of-year effects? (logical)

calendar_time

Residualize out calendar-time effects? (logical)

product_group_trend

Residualize out product-group-specific trends?

weight_var

Optional. The name of the variable to weight the regressions when residualizing (character).

Details

remove_time_trends is meant to residualize data in a variety of ways, depending on what the user wants. Some of these options are mutually exclusive. These include the options month_dummies and calendar_time - both cannot be TRUE, as they would be collinear. Additionally, the code does not allow product_group_trend and calendar_time to both be TRUE.

For the pictures in calendar time, we should try the following: de-trend and adjust for seasonality.

The following are taken from an email from Lancelot on 11/22/2018:

A) Take the sample that you create (in your R code) with theProductXCounty level data and regress the outcome that we want to plot (sales or prices) on a variable indicating the number of months since january 2008 (so that we estimate a linear time trend). Weigh the regression by January 2008 sales. Then take the residuals and take the average for each "group" (increase, decrease, no change) - weigh the observations by january 2008 sales when you compute the averages. (args: month_dummies = F)

B) Another version would fit a different time trend by "product group" (interact number of months since january 2008 with a dummy for each product group). Then take residuals, average over counties within each group and plot. (args: month_dummies = F, product_group_trend = T)

C) Do A) again but include a dummy for which month of the year in the regression (so a dummy for january, a dummy for february,...). Then take residuals, average over counties within each group and plot. (code is set up) (args: month_dummies = T)

D) Do B) again but include a dummy for which month of the year interacted with a product group specific dummy. Then take residuals, average over counties within each group and plot. (args: month_dummies = T, product_group_trend = T)

E) Instead of a time trend and month dummy, just take out calendar time effects (so regress on a dummy for each calendar time, take residuals, average over counties within each group and plot). (code is set up) (args: month_dummies = F, calendar_time = T)


johnnybonney/sales.taxes documentation built on Dec. 14, 2018, 3:03 p.m.