pdSort#
Purpose#
Sorts panel data by group and then by date variable.
Format#
- pd_sorted = pdSort(df[, groupvar, datevar])#
- Parameters:
df (Dataframe) – Contains long-form panel data with \(N_i x T_i\) rows and K columns.
groupvar (String) – Optional, name of the variable used to identify group membership for panel observations. Defaults to the first categorical or string variable in the dataframe.
datevar (String) – Optional, name of the variable used to identify dates for panel observations. Defaults to the first date variable in the dataframe.
- Returns:
pd_sorted (Dataframe) – A dataframe containing the sorted panel data.
Remarks#
This function takes long-form panel data. To transform wide data to long-form data see dfLonger()
.
This function sorts panel data by the specified groupvar and datevar, ensuring the data is arranged in the correct order for panel data analysis.
If groupvar is not provided, the function defaults to the first categorical or string variable in the dataframe.
If datevar is not provided, the function defaults to the first date variable in the dataframe.
Sorting panel data is essential for consistent results in other panel data functions, such as pdLag()
, pdDiff()
, and pdTimeSpans()
.
See also
sort()
, sortmc()