Title: | A Bit of Glue Between R and Stata |
---|---|
Description: | A simple R -> Stata interface allowing the user to execute Stata commands (both inline and from a .do file) from R. |
Authors: | Luca Braglia [aut, cre] |
Maintainer: | Luca Braglia <[email protected]> |
License: | GPL-3 |
Version: | 1.1.1 |
Built: | 2024-11-10 05:14:37 UTC |
Source: | https://github.com/lbraglia/rstata |
Set Stata binary (among found alternatives) path. These settings are
lost when R is closed, therefore you should consider adding a
options("RStata.StataPath")
line in your .Rprofile
.
chooseStataBin()
chooseStataBin()
A simple R -> Stata interface allowing the user to execute Stata commands (both inline and from a .do file) from R.
Function that sends commands to a Stata process.
stata( src = stop("At least 'src' must be specified"), data.in = NULL, data.out = FALSE, stata.path = getOption("RStata.StataPath", stop("You need to set up a Stata path; ?chooseStataBin")), stata.version = getOption("RStata.StataVersion", stop("You need to specify your Stata version")), stata.echo = getOption("RStata.StataEcho", TRUE), ... )
stata( src = stop("At least 'src' must be specified"), data.in = NULL, data.out = FALSE, stata.path = getOption("RStata.StataPath", stop("You need to set up a Stata path; ?chooseStataBin")), stata.version = getOption("RStata.StataVersion", stop("You need to specify your Stata version")), stata.echo = getOption("RStata.StataEcho", TRUE), ... )
src |
character vector of length 1 (path to |
data.in |
|
data.out |
logical value. If |
stata.path |
Stata command to be used |
stata.version |
Version of Stata used |
stata.echo |
logical value. If |
... |
parameter passed to |
## Not run: ## Single command stata("help regress") #<- this won't work in Windows dued to needed # batch mode ## Many commands stata_src <- ' version 10 set more off sysuse auto reg mpg weight ' stata(stata_src) ## External .do file stata("foo.do") ## Data input to Stata x <- data.frame(a = rnorm(3), b = letters[1:3]) stata( "sum a", data.in = x) ## Data output from Stata (eg obtain 'auto' dataset) auto <- stata("sysuse auto", data.out = TRUE) head(auto) ## Data input/output (y <- stata("replace a = 2", data.in = x, data.out = TRUE)) ## End(Not run)
## Not run: ## Single command stata("help regress") #<- this won't work in Windows dued to needed # batch mode ## Many commands stata_src <- ' version 10 set more off sysuse auto reg mpg weight ' stata(stata_src) ## External .do file stata("foo.do") ## Data input to Stata x <- data.frame(a = rnorm(3), b = letters[1:3]) stata( "sum a", data.in = x) ## Data output from Stata (eg obtain 'auto' dataset) auto <- stata("sysuse auto", data.out = TRUE) head(auto) ## Data input/output (y <- stata("replace a = 2", data.in = x, data.out = TRUE)) ## End(Not run)