stata: Send commands to a Stata process

Description Usage Arguments Examples

Description

Function that sends commands to a Stata process.

Usage

1
2
3
4
5
6
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), ...)

Arguments

src

character vector of length 1 (path to .do file) or more (a set of stata commands). See examples.

data.in

data.frame to be passed to Stata

data.out

logical value. If TRUE, the data at the end of the Stata command are returned to R.

stata.path

Stata command to be used

stata.version

Version of Stata used

stata.echo

logical value. If TRUE stata text output will be printed

...

parameter passed to write.dta

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
## 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)

RStata documentation built on May 1, 2019, 10:26 p.m.