mod_marg: Marginal Effects

Description Usage Arguments Details Value See Also Examples

Description

Run a model in Stata and return marginal or predicted effects for you

Usage

1
2
mod_marg(model, margs, df, do_file_name, wd, limit = 10,
  dta_file_name = "tmp.dta", verbose = F)

Arguments

model

string of the desired model (in stata syntax)

margs

list of strings, each of which should represent a margins command (in stata syntax) and have a name

df

data frame

do_file_name

string of what the do file should be called

wd

working directory for storing stata files

limit

time limit (in seconds) on how long stata should run, defaults to 10 seconds

dta_file_name

string, name of dta file and defaults to 'tmp.dta'

verbose

defaults to FALSE

Details

You will need to install estout in Stata for this to run. You can just run stata ssc install estout, replace from the command line.

To improve performance, try to only pass the variables of the data frame that you actually need.

If the code errors out, you should always look at the log file that is generated from the analysis. You should be able to find that in the working directory that you set. The other thing that you might want to do is delete any temporary text files that were created (they will have the names of the list items you passed in the margs parameter).

Some notes on idiosyncratic Stata things. First, it doesn't handle periods in dataframe names, so you'll want to fix that in your original dataset. Second, the variable names can only be so long, so if you have very long names, you should rename them before you pass them through this argument.

Value

a list containing model output and margins output

See Also

http://www.stata.com/help.cgi?margins

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
data(mtcars)
mod_marg(model = 'logit vs c.mpg##i.am',
         margs = list(
           m1 = 'margins am',
           m2 = 'margins, dydx(am)'
         ),
         df = mtcars[, c('vs', 'mpg', 'am')],
         do_file_name = 'cars.do',
         wd = '~/',
         verbose = TRUE)

anniejw6/rsMarg documentation built on May 10, 2019, 11:52 a.m.