I'm trying to call Stata functions from R and I need to pass more information from one program to the other than just a simple dataset. As a workaround, I simply built string variables that hold the other pieces of information (for example, a variable name that changes dynamically in my R program).

In Stata now, I would like to get the value of this variable (which is a variable name actually) to use it in my regression. Here is an example:

Code:
sysuse auto, clear

* R runs through a loop where "somename" changes many times so I want to use
* it dynamically in Stata. Say here we are at this one:
gen somename="trunk"

* now I want to use the value of "somename" (which is the variable name "trunk")
* in a regression that should output:

reg price mpg trunk

* here is how I would usually do this
local myname trunk
reg price mpg `myname'
But I don't know how I can get the information from the "somename" variable to my "myname" local. I've tried this:

Code:
levelsof(somename)
which already looks like a macro but I don't know how to call it later. This post here tells me to use display but that doesn't seem to work with levelsof.

Code:
local myname levelsof(somename)
local myname display levelsof(somename)
Any help would be appreciated!