Using Regression to Test the Projections
After visually inspecting the data, you decide that you also want to use regression analysis to determine whether there is a statistically significant shift in the trend from the historical revenues to the projected revenues. Recall you have to create a trend (trend
) and a shift (shift
) variable.
For this exercise, the revenue data you created in the prior exercise is stored in the rev
object. In that data, you will have two time series: historical revenues (hist_rev
) and projected revenues (proj_rev
). Historical revenues has positive values for the first 10 years of historical data and 0 for projection period. Projected revenues has 0 for the first 10 years and positive values during the projection period.
This exercise is part of the course
Equity Valuation in R
Exercise instructions
- Create a single revenue series that adds both historical and projected data.
- Add a trend variable to
rev_all_df
usingseq()
. - Add a shift variable to
rev_all_df
usingifelse()
. - Regress
rev_all
ontrend
andshift
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a data frame of single series
rev_all <- ___
rev_all_df <- data.frame(rev_all)
# Create Trend Variable
rev_all_df$trend <- seq(___, nrow(rev_all_df), ___)
# Create Shift Variable
rev_all_df$shift <- ifelse(rev_all_df$trend <= 7, ___, ___)
# Run regression
reg <- lm(___, data = rev_all_df)
summary(reg)