Description Usage Arguments Details Examples
View source: R/panel_convert.R
This function takes panel data objects declared using pmdplyr
(pibble
/tbl_pb
), tsibble
(tsibble
/tbl_ts
), plm
(pdata.frame
), and panelr
(panel_data
) and converts to one of the other three formats for use with functions in those packages.
1 | panel_convert(data, to, ...)
|
data |
Data frame - a |
to |
Character variable set to |
... |
Additional arguments to be sent to, respectively, |
Any grouping will be lost. You must have the relevant package installed to convert to the type for that package. Conversions from pdata.frame
will be improved if sjlabelled
is also installed.
When using panel_convert
, be aware of the requirements that each type has:
Feature/Requirement | pibble | tsibble | pdata.frame | panel_data |
ID | .i | key | index[1] | id |
Time | .t | index | index[2] | wave |
Gap control | .d | regular | No | No |
ID must exist | No | No | Yes | Yes |
Time must exist | No | Yes | Yes | Yes[1] |
Only one ID variable[2] | No | No | Yes | Yes |
Unique identification | No | Yes | No[3] | No[3] |
[1] pdata.frame
does not require that time be provided, but if not provided will create it based on original ordering of the data. The pdata.frame
option to set index
equal to an integer for a balanced panel and have it figure out the rest by itself is not supported.
[2] Use pmdplyr::id_variable()
to generate a single ID variable from multiple if one is required.
[3] pdata.frame
and panel_data
do not require that ID and time uniquely identify the observations on declaring the data, but functions in these packages may not work correctly without unique identification.
In addition to the above, be aware that the different packages have different requirements on which variable classes can be Time variables. pmdplyr::time_variable()
can build an integer variable that will work in all packages.
You may run into some trouble if your data contains variables by the names panel_convert_id
, panel_convert_time
, pibble_d
, or panel_convert_regular
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | # Only run examples if the relevant packages are installed
pkgs <- utils::installed.packages()
data(Scorecard)
# The example will turn a pibble to everything else
# But starting with another type will of course work!
S_pibble <- as_pibble(Scorecard, .i = unitid, .t = year)
# Get a tsibble
if ("tsibble" %in% pkgs) {
head(panel_convert(S_pibble, to = "tsibble"))
}
# Now for pdata.frame
if ("plm" %in% pkgs) {
head(panel_convert(S_pibble, to = "plm"))
}
# And finally panel_data
if ("panelr" %in% pkgs) {
head(panel_convert(S_pibble, to = "panelr"))
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.