A function to calculate unit-specific principal components, given panel data
get_principal_components(
xformula,
data,
idname,
tname,
n_components = NULL,
ret_wide = FALSE,
ret_id = FALSE
)
a data.frame containing the original data with the principal components appended
a formula specifying the variables to use in the principal component analysis
a data.frame containing the panel data
the name of the column containing the unit id
the name of the column containing the time period
the number of principal components to retain, the default is NULL which will result in all principal components being retained
whether to return the data in wide format (where the number of rows is equal to n = length(unique(data[[idname]])) or long format (where the number of rows is equal to nT = nrow(data)). The default is FALSE, so that long data is returned by default.
whether to return the id column in the output data.frame. The default is FALSE.