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.

panel_convert(data, to, ...)

Arguments

data

Data frame - a pibble, tsibble, pdata.frame, or panel_data object.

to

Character variable set to "pmdplyr", "pibble", "tbl_pb", "tsibble", "tbl_ts", "plm", "pdata.frame", "panelr" or "panel_data" indicating the type/package to be converted to.

...

Additional arguments to be sent to, respectively, as_pibble(), tsibble::as_tsibble(), plm::pdata.frame(), or panelr::panel_data().

Details

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/Requirementpibbletsibblepdata.framepanel_data
ID.ikeyindex[1]id
Time.tindexindex[2]wave
Gap control.dregularNoNo
ID must existNoNoYesYes
Time must existNoYesYesYes[1]
Only one ID variable[2]NoNoYesYes
Unique identificationNoYesNo[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.

Examples

# 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")) }
#> # A tsibble: 6 x 9 [1Y] #> # Key: unitid [1] #> unitid inst_name state_abbr pred_degree_awa~ year earnings_med #> <int> <chr> <chr> <int> <int> <int> #> 1 100654 Alabama ~ AL 3 2007 36600 #> 2 100654 Alabama ~ AL 3 2009 32600 #> 3 100654 Alabama ~ AL 3 2011 31400 #> 4 100654 Alabama ~ AL 3 2012 30300 #> 5 100654 Alabama ~ AL 3 2013 29900 #> 6 100654 Alabama ~ AL 3 2014 31000 #> # ... with 3 more variables: count_not_working <int>, count_working <int>, #> # repay_rate <dbl>
# Now for pdata.frame if ("plm" %in% pkgs) { head(panel_convert(S_pibble, to = "plm")) }
#> unitid inst_name state_abbr #> 100654-2007 100654 Alabama A & M University AL #> 100654-2009 100654 Alabama A & M University AL #> 100654-2011 100654 Alabama A & M University AL #> 100654-2012 100654 Alabama A & M University AL #> 100654-2013 100654 Alabama A & M University AL #> 100654-2014 100654 Alabama A & M University AL #> pred_degree_awarded_ipeds year earnings_med count_not_working #> 100654-2007 3 2007 36600 116 #> 100654-2009 3 2009 32600 202 #> 100654-2011 3 2011 31400 214 #> 100654-2012 3 2012 30300 239 #> 100654-2013 3 2013 29900 246 #> 100654-2014 3 2014 31000 212 #> count_working repay_rate #> 100654-2007 1139 NA #> 100654-2009 1410 NA #> 100654-2011 1532 NA #> 100654-2012 1601 NA #> 100654-2013 1741 0.5118364 #> 100654-2014 1784 0.4202658
# And finally panel_data if ("panelr" %in% pkgs) { head(panel_convert(S_pibble, to = "panelr")) }
#> Warning: The `add` argument of `group_by()` is deprecated as of dplyr 1.0.0. #> Please use the `.add` argument instead. #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_warnings()` to see where this warning was generated.
#> # Panel data: 6 x 9 #> # entities: unitid [1] #> # wave variable: year [2007, 2009, 2011, ... (6 waves)] #> unitid year inst_name state_abbr pred_degree_awa~ earnings_med #> <fct> <int> <chr> <chr> <int> <int> #> 1 100654 2007 Alabama ~ AL 3 36600 #> 2 100654 2009 Alabama ~ AL 3 32600 #> 3 100654 2011 Alabama ~ AL 3 31400 #> 4 100654 2012 Alabama ~ AL 3 30300 #> 5 100654 2013 Alabama ~ AL 3 29900 #> 6 100654 2014 Alabama ~ AL 3 31000 #> # ... with 3 more variables: count_not_working <int>, count_working <int>, #> # repay_rate <dbl>