bvkrauth / rcr

RCR package for Stata, R, and Python
MIT License
0 stars 2 forks source link

Add Stata support for factor variables and time series operators #60

Closed bvkrauth closed 1 year ago

bvkrauth commented 2 years ago

Currently the Stata command rejects varlists that include factor variables or time series operators. In principle, it should be possible to expand those varlists out and use them.

bvkrauth commented 2 years ago

Code:

* Setup
sysuse census, clear
* Run the linear regression, with factor and/or time series variables
reg pop marriage i.region
* RCR will not allow this variable list
noisily capture rcr pop marriage i.region

* To fix this, use the Stata command fvrevar to expand the factor/ts variables.
* fvrevar will:
*  1. Create temporary variables for all of the factor levels and lagged variables
*  2. Return the variable list (in r(varlist) with these new temporary variables
*     in place of the factor/ts variables
fvrevar marriage i.region
* Copy the new variable list into a macro
local vars = r(varlist)
* See what's in there
di "`vars'"
* Note that fvrevar includes all factor levels including the base level,
* so our variable list is collinear
* We can fix that by using the _rmcoll command, which creates a new
* variable list that omits collinear variables
_rmcoll `vars', forcedrop
* Copy the new variable list into a macro
local vars = r(varlist)
* See what's in there
di "`vars'"
* Now we can use this variable list in the rcr command
rcr pop `vars'