ff_panel_expand_longandwide: Append Group Mean Lagged Values as Additional Panel Variables

Description Usage Arguments Value Author(s) References Examples

View source: R/ff_panel_expand.R

Description

There is a variable recorded for a panel, and a variable with date info, and another with obs info Compute averages over sub-groups of dates for each variable, with different ways of specifying date subgroups. average(svr_data) over svr Reshape data so each date is a variable for selected subset of key variables Merge results from 2 back to main, so that each indi/date observation has as variables all lagged and forward information as additional variables. Append not n lag m forward, but full history as additional variables Doing this allows for lagged intereaction that are time specific in an arbitrary way.

Usage

1
ff_panel_expand_longandwide(df, svr_id_t, svr_id_i, svr_data)

Arguments

svr_id_t

string time variable name

svr_id_i

string individual ID name

svr_data

string variable name

Value

a long panel frame with wide expansion of group mean lagged vars

Author(s)

Fan Wang, http://fanwangecon.github.io

References

https://fanwangecon.github.io/REconTools/reference/ff_panel_expand_longandwide.html https://fanwangecon.github.io/REconTools/articles/fv_panel_expand_longandwide.html https://github.com/FanWangEcon/REconTools/blob/master/R/ff_panel_expand.R

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
library(dplyr)
df_hw_cebu <- df_hgt_wgt %>% filter(S.country == 'Cebu' & svymthRound <= 24 & svymthRound > 0)
df_hw_cebu <- df_hw_cebu %>% mutate(mth6 = recode(svymthRound,
                                    `0`="m00t06", `2`="m00t06", `4`="m00t06", `6`="m00t06",
                                    `8`="m08t12", `10`="m08t12", `12`="m08t12",
                                    `14`="m14t18", `16`="m14t18", `18`="m14t18",
                                    `20`="m20t24", `22`="m20t24", `24`="m20t24"))
df_longandwide <- ff_panel_expand_longandwide(df_hw_cebu,
                                         svr_id_t = 'mth6',
                                         svr_id_i = 'indi.id',
                                         svr_data = 'cal')
print(df_longandwide %>% select(indi.id, svymthRound, mth6, cal, matches('mth6'), everything()), n=100)

FanWangEcon/REconTools documentation built on Jan. 21, 2022, 10:28 p.m.