Hi, I'm hoping to run R's lasso (glmnet package) on a set of variables from Stata, then bring the *names* of the subset variables into Stata as a global. I'm hoping for advice on strategy.
I've often before run .R code from Stata using vanilla --- I would export a dataset from Stata, then run the .R code on it using vanilla, then produce a .dta file at the end of the .R code, and then use that .dta file in the latter part of the Stata .do file.
However, this time I want to import a set of character strings (4 of them, 25-75 characters long) produced by R into Stata, not as data but as macros. I'm aware that I could export the character string vector as a 1-variable dataset into Stata, and then probably loop through the variable values to create a macro of the names... but that seems quite round-about.
Using rcall seems likely to be the best option? I assume that I could load glmnet and run lasso using rcall, after creating R matrices out of Stata matrices... but I'm having trouble doing that first step. I get the error "too many numeric literals" when try to save a Stata matrix as an R matrix, as I note at the end of this (error-relevant) thread here: https://www.statalist.org/forums/for...ls-r-130/page2
Thanks in advance for any tips on best use of R-related code/commands!
I've often before run .R code from Stata using vanilla --- I would export a dataset from Stata, then run the .R code on it using vanilla, then produce a .dta file at the end of the .R code, and then use that .dta file in the latter part of the Stata .do file.
However, this time I want to import a set of character strings (4 of them, 25-75 characters long) produced by R into Stata, not as data but as macros. I'm aware that I could export the character string vector as a 1-variable dataset into Stata, and then probably loop through the variable values to create a macro of the names... but that seems quite round-about.
Using rcall seems likely to be the best option? I assume that I could load glmnet and run lasso using rcall, after creating R matrices out of Stata matrices... but I'm having trouble doing that first step. I get the error "too many numeric literals" when try to save a Stata matrix as an R matrix, as I note at the end of this (error-relevant) thread here: https://www.statalist.org/forums/for...ls-r-130/page2
Thanks in advance for any tips on best use of R-related code/commands!
Comment