Time series and forecasting
Start with the expanded example for each command. Open the variants for options and alternative R approaches. Read the qualifications before adapting the code.
ac
Autocorrelation function
Stata
ac y, lags(12)R Package:stats
stats::acf(y, lag.max = 12, plot = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. R returns numeric correlations; request plotting separately.
arch
GARCH(1,1) conditional-variance model
Stata
arch y, arch(1) garch(1) noconstantR Package:tseries
tseries::garch(as.numeric(y), order = c(1, 1), trace = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Fit a mean model separately; optimization and initialization differ.
ARCH(1) conditional-variance model
Stata
arch y, arch(1) noconstantR Package:tseries
tseries::garch(as.numeric(y), order = c(0, 1), trace = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. tseries::garch models zero-mean observations; remove or explicitly model the conditional mean first.
arfima
Fractionally integrated ARMA estimation
Stata
arfima y, ar(1) ma(1)R Package:fracdiff
fracdiff::fracdiff(y, nar = 1, nma = 1)Differs from Stata Fixed workflow; adapt the named data columns explicitly. fracdiff uses approximate likelihood and a different MA sign convention.
arfimasoc
Fractional-ARMA order comparison
Stata
arfimasoc y, maxar(1) maxma(1)R Package:fracdiff
{ grid <- expand.grid(p = 0:1, q = 0:1); grid$AIC <- mapply(function(p, q) { f <- fracdiff::fracdiff(y, nar = p, nma = q); -2 * f$log.likelihood + 2 * (p + q + 2) }, grid$p, grid$q); grid }Fixed workflow; adapt the named data columns explicitly. Approximate-likelihood order-selection workflow; no numerical parity claim.
arima
ARMAX with external regressor
Stata
arima y x, arima(1,0,0)R Package:stats
stats::arima(y, order = c(1, 0, 0), xreg = x)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
11 more examples and alternatives
Seasonally differenced moving average
Stata
arima y, arima(0,0,0) sarima(0,1,1,4)R Package:stats
stats::arima(y, order = c(0, 0, 0), seasonal = list(order = c(0, 1, 1), period = 4))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
Seasonal autoregression
Stata
arima y, arima(0,0,0) sarima(1,0,0,4)R Package:stats
stats::arima(y, order = c(0, 0, 0), seasonal = list(order = c(1, 0, 0), period = 4))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
MA(1) with intercept
Stata
arima y, arima(0,0,1)R Package:stats
stats::arima(y, order = c(0, 0, 1))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
Integrated moving-average model
Stata
arima y, arima(0,1,1)R Package:stats
stats::arima(y, order = c(0, 1, 1))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
AR(1) with intercept
Stata
arima y, arima(1,0,0)R Package:stats
stats::arima(y, order = c(1, 0, 0))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
State-space maximum-likelihood estimation
Stata
arima y, arima(1,0,0) diffuseR Package:stats
stats::arima(y, order = c(1, 0, 0), method = "ML", SSinit = "Rossignol2011")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
Zero-mean autoregression
Stata
arima y, arima(1,0,0) noconstantR Package:stats
stats::arima(y, order = c(1, 0, 0), include.mean = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
ARMA(1,1)
Stata
arima y, arima(1,0,1)R Package:stats
stats::arima(y, order = c(1, 0, 1))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
ARMA estimation using ML
Stata
arima y, arima(1,0,1)R Package:stats
stats::arima(y, order = c(1, 0, 1), method = "ML")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Explicit likelihood setting avoids relying on R’s default CSS-ML initialization.
ARMA estimation using CSS
Stata
arima y, arima(1,0,1) // conditional least-squares alternativeR Package:stats
stats::arima(y, order = c(1, 0, 1), method = "CSS")Fixed workflow; adapt the named data columns explicitly. Conditional sum of squares is a workflow alternative, not Stata’s default likelihood.
ARIMA with first difference
Stata
arima y, arima(1,1,0)R Package:stats
stats::arima(y, order = c(1, 1, 0))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Parameterization, initialization and likelihood conventions differ; compare selected model, not default output.
arimasoc
ARMA information-criterion grid
Stata
arimasoc y, maxar(2) maxma(2)R Package:stats
{ grid <- expand.grid(p = 0:2, q = 0:2); grid$AIC <- mapply(function(p, q) stats::AIC(stats::arima(y, order = c(p, 0, q), method = "ML")), grid$p, grid$q); grid }Fixed workflow; adapt the named data columns explicitly. Comparable-sample model-selection workflow; R and Stata likelihood constants may differ.
corrgram
Autocorrelation and partial-autocorrelation table
Stata
corrgram y, lags(8)R Package:stats
list(ac = stats::acf(y, lag.max = 8, plot = FALSE), pac = stats::pacf(y, lag.max = 8, plot = FALSE))Differs from Stata Fixed workflow; adapt the named data columns explicitly. R returns numeric correlations; request plotting separately.
cumsp
Cumulative spectral distribution
Stata
cumsp yR Package:stats
{ sp <- stats::spectrum(y, plot = FALSE, taper = 0); data.frame(frequency = sp$freq, cumulative = cumsum(sp$spec) / sum(sp$spec)) }Fixed workflow; adapt the named data columns explicitly. Computes curve data; confidence bands are not included.
dfgls
DF-GLS unit-root test with trend
Stata
dfgls y, maxlag(4) R Package:urca
urca::ur.ers(y, type = "DF-GLS", model = "trend", lag.max = 4)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Lag-selection and finite-sample critical values may differ.
DF-GLS unit-root test with constant
Stata
dfgls y, maxlag(4) notrendR Package:urca
urca::ur.ers(y, type = "DF-GLS", model = "constant", lag.max = 4)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Lag-selection and finite-sample critical values may differ.
dfuller
ADF unit-root test with drift and 0 augmentation lags
Stata
dfuller y, lags(0)R Package:urca
urca::ur.df(y, type = "drift", lags = 0)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match deterministic terms, sample window and lag selection; critical-value implementations can differ.
ADF unit-root test with none and 0 augmentation lags
Stata
dfuller y, lags(0) noconstantR Package:urca
urca::ur.df(y, type = "none", lags = 0)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match deterministic terms, sample window and lag selection; critical-value implementations can differ.
ADF unit-root test with trend and 0 augmentation lags
Stata
dfuller y, lags(0) trendR Package:urca
urca::ur.df(y, type = "trend", lags = 0)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match deterministic terms, sample window and lag selection; critical-value implementations can differ.
ADF unit-root test with drift and 2 augmentation lags
Stata
dfuller y, lags(2)R Package:urca
urca::ur.df(y, type = "drift", lags = 2)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match deterministic terms, sample window and lag selection; critical-value implementations can differ.
ADF unit-root test with none and 2 augmentation lags
Stata
dfuller y, lags(2) noconstantR Package:urca
urca::ur.df(y, type = "none", lags = 2)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match deterministic terms, sample window and lag selection; critical-value implementations can differ.
1 more examples and alternatives
ADF unit-root test with trend and 2 augmentation lags
Stata
dfuller y, lags(2) trendR Package:urca
urca::ur.df(y, type = "trend", lags = 2)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Match deterministic terms, sample window and lag selection; critical-value implementations can differ.
fcast
Iterated bivariate VAR point forecasts
Stata
fcast compute pred, step(8)R Package:stats
{ out <- matrix(NA_real_, 8, 2); last <- tail(Y, 1); intercept <- stats::coef(fit)[1, ]; for (h in 1:8) { last <- matrix(intercept + drop(A %*% drop(last)), nrow = 1); out[h, ] <- last }; colnames(out) <- colnames(Y); out }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Point forecasts only; no system forecast-error covariance or interval calculation.
forecast
Eight-period ARIMA forecast
Stata
forecast solve, begin(161)R Package:forecast
forecast::forecast(fit, h = 8)Fixed workflow; adapt the named data columns explicitly. Single-equation forecasting workflow; forecast system identities are not translated.
Forecast with ninety-percent prediction intervals
Stata
forecast solve, begin(161) periods(8) simulate(errors, statistic(stddev, prefix(sd_)))R Package:forecast
forecast::forecast(fit, h = 8, level = 90)Fixed workflow; adapt the named data columns explicitly. Single-equation forecasting workflow; forecast system identities are not translated. R produces analytic 90% prediction intervals; the Stata example instead simulates forecast standard deviations, requiring a separate interval calculation.
One-step fitted values from ARIMA
Stata
forecast solve, begin(161) staticR Package:forecast
stats::fitted(forecast::Arima(y, order = c(1, 0, 0)))Fixed workflow; adapt the named data columns explicitly. In-sample one-step prediction workflow; Stata’s forecast model setup is separate.
irf
Reduced-form VAR(1) impulse-response matrices
Stata
irf create model, step(8)R Package:base
{ powers <- vector("list", 9); powers[[1]] <- diag(2); for (h in 2:9) powers[[h]] <- powers[[h - 1]] %*% A; powers }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Unit reduced-form innovation responses; orthogonalized structural responses require an identification scheme.
Cholesky-orthogonalized VAR responses
Stata
irf create model, step(8) // orthogonalized responsesR Package:base
{ impact <- t(chol(crossprod(stats::residuals(fit)) / stats::nobs(fit))); powers <- vector("list", 9); powers[[1]] <- impact; for (h in 2:9) powers[[h]] <- A %*% powers[[h - 1]]; powers }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Recursive ordering is y then x; covariance divisor and identifying assumptions matter.
ivlpirf
Instrumental-variable local-projection point responses
Stata
ivlpirf y, endogenous(x = z) step(8) lags(1)R Package:AER
vapply(0:8, function(h) { i <- 2:(nrow(data) - h); d <- data.frame(outcome = data$y[i + h], impulse = data$x[i], Ly = data$y[i - 1], instrument = data$z[i]); unname(stats::coef(AER::ivreg(outcome ~ impulse + Ly | instrument + Ly, data = d))[2]) }, numeric(1))Fixed workflow; adapt the named data columns explicitly. Horizonwise 2SLS workflow; instrument validity, normalization and HAC inference require separate decisions.
lpirf
Local-projection dynamic response to an external impulse
Stata
lpirf y, exog(x) step(8) lags(1)R Package:stats
vapply(0:8, function(h) { i <- 2:(nrow(data) - h); unname(stats::coef(stats::lm(data$y[i + h] ~ data$x[i] + data$y[i - 1] + data$x[i - 1]))[2]) }, numeric(1))Fixed workflow; adapt the named data columns explicitly. Simple horizonwise point-estimation workflow; HAC inference and system restrictions must be added for research use.
newey
Newey-West HAC coefficient inference
Stata
newey y x, lag(4)R Package:sandwich
{ fit <- stats::lm(y ~ x, data = data); lmtest::coeftest(fit, vcov. = sandwich::NeweyWest(fit, lag = 4, prewhite = FALSE, adjust = TRUE)) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Explicit bandwidth, prewhitening and finite-sample correction; align those choices.
pac
Partial autocorrelation function
Stata
pac y, lags(12)R Package:stats
stats::pacf(y, lag.max = 12, plot = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. R returns numeric correlations; request plotting separately.
pergram
Raw periodogram
Stata
pergram yR Package:stats
stats::spectrum(y, plot = FALSE, taper = 0, detrend = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Normalization and default tapering can differ.
pperron
Phillips-Perron Z-alpha test with constant
Stata
pperron y, lags(4) R Package:urca
urca::ur.pp(y, type = "Z-alpha", model = "constant", use.lag = 4)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Stata reports several statistics together; R selects one statistic. Kernel and deterministic terms must be matched.
Phillips-Perron Z-tau test with constant
Stata
pperron y, lags(4) R Package:urca
urca::ur.pp(y, type = "Z-tau", model = "constant", use.lag = 4)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Stata reports several statistics together; R selects one statistic. Kernel and deterministic terms must be matched.
Phillips-Perron Z-alpha test with trend
Stata
pperron y, lags(4) trendR Package:urca
urca::ur.pp(y, type = "Z-alpha", model = "trend", use.lag = 4)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Stata reports several statistics together; R selects one statistic. Kernel and deterministic terms must be matched.
Phillips-Perron Z-tau test with trend
Stata
pperron y, lags(4) trendR Package:urca
urca::ur.pp(y, type = "Z-tau", model = "trend", use.lag = 4)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Stata reports several statistics together; R selects one statistic. Kernel and deterministic terms must be matched.
predict
Dynamic ARIMA forecast and standard errors
Stata
predict yhat, y dynamic(161)R Package:stats
stats::predict(fit, n.ahead = 8)Fixed workflow; adapt the named data columns explicitly. Single-equation forecasting workflow; forecast system identities are not translated.
psdensity
Parametric AR(1) spectral density
Stata
arima y, arima(1,0,0)
psdensity density, n(64)R Package:stats
{ phi <- unname(fit$coef["ar1"]); omega <- seq(0, pi, length.out = 64); data.frame(frequency = omega / (2 * pi), density = fit$sigma2 / (2 * pi * Mod(1 - phi * exp(-1i * omega))^2)) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Frequency and density normalization conventions must be reconciled.
rolling
Expanding-window recursive regression
Stata
rolling _b, window(40) recursive: regress y xR Package:stats
t(vapply(40:nrow(data), function(i) stats::coef(stats::lm(y ~ x, data[seq_len(i), ])), numeric(2)))Differs from Stata Fixed workflow; adapt the named data columns explicitly. Uses a fixed first observation and increasing estimation endpoint.
Rolling-window regression coefficients
Stata
rolling _b, window(40): regress y xR Package:zoo
zoo::rollapply(data, width = 40, FUN = function(z) stats::coef(stats::lm(y ~ x, data = as.data.frame(z))), by.column = FALSE, align = "right")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Output rows correspond to complete right-aligned windows; failures need explicit handling in production.
Rolling sample volatility
Stata
rolling sd=r(sd), window(20): summarize yR Package:zoo
zoo::rollapply(y, width = 20, FUN = stats::sd, align = "right")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Sample standard deviation, not model-implied conditional volatility.
sspace
Local-linear-trend state-space model
Stata
sspace (level L.level L.slope, state noconstant) (slope L.slope, state noconstant) (y level, noconstant)R Package:stats
stats::StructTS(y, type = "trend")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Specific local-linear-trend model; initialization can differ.
Local-level state-space model
Stata
sspace (level L.level, state noconstant) (y level, noconstant)R Package:stats
stats::StructTS(y, type = "level")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Specific local-level model equivalent; sspace supports a much wider model class.
tsfilter
Baxter-King approximate band-pass cycle
Stata
tsfilter bk cycle = y, minperiod(6) maxperiod(32) smaorder(12)R Package:stats
{ K <- 12; j <- -K:K; low <- 2 * pi / 32; high <- 2 * pi / 6; w <- ifelse(j == 0, (high - low) / pi, (sin(high * j) - sin(low * j)) / (pi * j)); w <- w - mean(w); stats::filter(y, w, sides = 2) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Symmetric finite-order band-pass filter loses endpoint observations.
Hodrick-Prescott trend and cycle decomposition
Stata
tsfilter hp cycle = y, smooth(1600) trend(trend)R Package:base
{ n <- length(y); D <- diff(diag(n), differences = 2); trend <- drop(solve(diag(n) + 1600 * crossprod(D), as.numeric(y))); data.frame(trend = trend, cycle = as.numeric(y) - trend) }Differs from Stata Fixed workflow; adapt the named data columns explicitly. Complete regular series; this direct penalized least-squares solution uses the two-sided HP filter.
tsreport
Locate missing time periods
Stata
tsreport, reportR Package:base
data.frame(previous = head(data$t, -1), next_time = tail(data$t, -1), gap = diff(data$t))[diff(data$t) != 1, ]Fixed workflow; adapt the named data columns explicitly. Assumes integer unit-spaced time; date calendars need the intended interval definition.
tssmooth
Simple exponential smoothing
Stata
tssmooth exponential smooth = y, parms(.3)R Package:stats
stats::HoltWinters(y, alpha = .3, beta = FALSE, gamma = FALSE)Fixed workflow; adapt the named data columns explicitly. Initial values, endpoints and trend formulations differ; align before comparing.
Holt trend smoothing workflow
Stata
tssmooth hwinters smooth = yR Package:stats
stats::HoltWinters(y, gamma = FALSE)Fixed workflow; adapt the named data columns explicitly. Initial values, endpoints and trend formulations differ; align before comparing.
Centered five-term moving average
Stata
tssmooth ma smooth = y, window(2 1 2)R Package:stats
stats::filter(y, rep(1 / 5, 5), sides = 2)Fixed workflow; adapt the named data columns explicitly. Initial values, endpoints and trend formulations differ; align before comparing.
Trailing four-term moving average
Stata
tssmooth ma smooth = y, window(3 1 0)R Package:stats
stats::filter(y, rep(1 / 4, 4), sides = 1)Fixed workflow; adapt the named data columns explicitly. Initial values, endpoints and trend formulations differ; align before comparing.
Additive seasonal Holt-Winters smoothing
Stata
tssmooth shwinters smooth = yR Package:stats
stats::HoltWinters(y, seasonal = "additive")Fixed workflow; adapt the named data columns explicitly. Initial values, endpoints and trend formulations differ; align before comparing.
1 more examples and alternatives
Running-median nonlinear smoother
Stata
tssmooth nl smooth = y, smoother(3)R Package:stats
stats::runmed(as.numeric(y), k = 3, endrule = "median")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Endpoint rules should be checked separately before comparing.
ucm
Unobserved components: level
Stata
ucm y, model(llevel)R Package:stats
stats::StructTS(y, type = "level")Differs from Stata Fixed workflow; adapt the named data columns explicitly. R supports selected structural models; Stata ucm permits additional components and constraints.
Unobserved components: trend
Stata
ucm y, model(lltrend)R Package:stats
stats::StructTS(y, type = "trend")Differs from Stata Fixed workflow; adapt the named data columns explicitly. R supports selected structural models; Stata ucm permits additional components and constraints.
Unobserved components: BSM
Stata
ucm y, model(lltrend) seasonal(4)R Package:stats
stats::StructTS(y, type = "BSM")Differs from Stata Fixed workflow; adapt the named data columns explicitly. R supports selected structural models; Stata ucm permits additional components and constraints.
var
Unrestricted bivariate VAR(1) by equation OLS
Stata
var y x, lags(1)R Package:stats
stats::lm(cbind(y, x) ~ Ly + Lx, data = lagged)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Coefficient equivalent for an unrestricted common-sample VAR; system covariance reporting differs.
VAR with deterministic time trend
Stata
var y x, lags(1) exog(trend)R Package:stats
stats::lm(cbind(y, x) ~ Ly + Lx + seq_len(nrow(lagged)), data = lagged)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Trend origin affects intercepts; compare the same sample and trend indexing.
Zero-intercept bivariate VAR
Stata
var y x, lags(1) noconstantR Package:stats
stats::lm(cbind(y, x) ~ 0 + Ly + Lx, data = lagged)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Specify identical lag matrices and deterministic terms.
vargranger
Test whether y Granger-predicts x
Stata
var y x, lags(1)
vargrangerR Package:lmtest
lmtest::grangertest(x ~ y, order = 1, data = data)Differs from Stata Fit var y x, lags(1) before vargranger; Stata VAR otherwise defaults to lags(1 2). grangertest uses an F reference distribution, whereas vargranger reports a Wald chi-square; match direction and sample, and do not interpret predictability as structural causation.
Test whether x Granger-predicts y
Stata
var y x, lags(1)
vargrangerR Package:lmtest
lmtest::grangertest(y ~ x, order = 1, data = data)Differs from Stata Fit var y x, lags(1) before vargranger; Stata VAR otherwise defaults to lags(1 2). grangertest uses an F reference distribution, whereas vargranger reports a Wald chi-square; match direction and sample, and do not interpret predictability as structural causation.
varstable
Eigenvalues of the VAR(1) companion matrix
Stata
varstableR Package:base
eigen(A, only.values = TRUE)$valuesDiffers from Stata Fixed workflow; adapt the named data columns explicitly. Stability requires all companion roots strictly inside the unit circle.
vec
Rank-one vector error-correction model
Stata
vec y x, rank(1) lags(2)R Package:urca
urca::cajorls(urca::ca.jo(Y, type = "trace", ecdet = "none", K = 2, spec = "transitory"), r = 1)Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
vecrank
Test cointegration rank with an unrestricted intercept
Stata
vecrank y x, lags(2) trend(constant)R Package:urca
urca::ca.jo(Y, type = "trace", ecdet = "none", K = 2, spec = "transitory")Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
Johansen trace rank test with a restricted constant
Stata
vecrank y x, lags(2) trend(rconstant)R Package:urca
urca::ca.jo(Y, type = "trace", ecdet = "const", K = 2, spec = "transitory")Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
Johansen maximum-eigenvalue rank test with a restricted constant
Stata
vecrank y x, lags(2) trend(rconstant) maxR Package:urca
urca::ca.jo(Y, type = "eigen", ecdet = "const", K = 2, spec = "transitory")Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
Johansen trace rank test with a restricted trend
Stata
vecrank y x, lags(2) trend(rtrend)R Package:urca
urca::ca.jo(Y, type = "trace", ecdet = "trend", K = 2, spec = "transitory")Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
Johansen maximum-eigenvalue rank test with a restricted trend
Stata
vecrank y x, lags(2) trend(rtrend) maxR Package:urca
urca::ca.jo(Y, type = "eigen", ecdet = "trend", K = 2, spec = "transitory")Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
1 more examples and alternatives
Test cointegration rank with an unrestricted intercept
Stata
vecrank y x, lags(2) trend(constant) maxR Package:urca
urca::ca.jo(Y, type = "eigen", ecdet = "none", K = 2, spec = "transitory")Differs from Stata urca ecdet=“const” matches Stata trend(rconstant); ecdet=“none” includes an unrestricted intercept and matches trend(constant); ecdet=“trend” matches trend(rtrend). ca.jo does not provide Stata trend(none) or trend(trend). Match cointegrating-vector normalization before comparing coefficients.
wntestq
Ljung-Box test after AR(1) estimation
Stata
predict e, residuals
wntestq e, lags(8)R Package:stats
stats::Box.test(stats::residuals(fit), lag = 8, type = "Ljung-Box", fitdf = 1)Differs from Stata Fixed workflow; adapt the named data columns explicitly. R explicitly deducts the estimated AR parameter from the reference degrees of freedom.
Ljung-Box serial-correlation portmanteau test
Stata
wntestq y, lags(8)R Package:stats
stats::Box.test(y, lag = 8, type = "Ljung-Box")Differs from Stata Fixed workflow; adapt the named data columns explicitly. Use fitdf for tests on estimated-model residuals.
xcorr
Cross-correlation at positive and negative lags
Stata
xcorr y x, lags(8)R Package:stats
stats::ccf(y, x, lag.max = 8, plot = FALSE)Differs from Stata Fixed workflow; adapt the named data columns explicitly. Check lag sign conventions before interpreting lead-lag direction.