To make your monthly time series dataset start from May-1978 to Dec-2019 in R, you can use the ts()
function and specify the start and end dates.
Here's an example of how you can do this:
main.r373 chars11 lines
Regarding the number of lags to use for the Augmented Dickey-Fuller (ADF) test, it depends on the specific characteristics of your time series data. In general, you would want to choose a sufficient number of lags to capture the autocorrelation structure in the data.
To determine the optimal number of lags, you can use the kpss.test()
function from the tseries
package in R. This function provides automatic selection of the lag length based on the Kwiatkowski-Phillips-Schmidt-Shin (KPSS) test.
Here's an example of how to use the kpss.test()
function to determine the optimal number of lags for the ADF test:
main.r176 chars8 lines
The optimal_lags
variable will contain the recommended number of lags for the ADF test based on the results of the KPSS test.
Note that you may need to adjust the number of lags based on your specific dataset and the underlying theory of the phenomenon you are studying.
gistlibby LogSnag