function to df is a dataframe that is in tidy format with the variables in columns and a date column. gp_vec variable that is used in the group_by to estimate the slope for different metro areas y1 is the dependent variable x1 is the time trend transf_l is the label to be used in the transf column originally wrote this as part of the fred "work1_bk.R" script
# In writing the function above I had started with the following simple example 20 year empetot regression regdf <- tmbk_q filter(date >= start_20yr & date <= end_prior_q) group_by(area_sh) do(fiteq = lm((log(empetot)) ~ time(date), data = .))
get the coefficients by group in a tidy data_frame dfslope <- tidy(regdf, fiteq) filter(term == "time(date)") mutate(value = (((1+estimate)^4) -1)) mutate(transf = "gr20yr") mutate(variable = "empetot") select(area_sh, variable, transf, value)
get the summary statistics by group in a tidy data_frame dfsumm = glance(regdf, fiteq)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.