RStata
RStata copied to clipboard
Incorporates option to import Stata estimation results into R.
Allows users to run analyses in Stata and directly import the results for further processing, reporting, or plotting in R. The addition adds the relevant option, returns.out, to the stata() function. If selected, Stata code is appended to the SRC object which loops through the active and stored return and ereturn results in Stata and writes them to an excel file. Then the excel file is read into a list in R and returned as the output.
If both data.out and returns.out are selected, a list is returned in which the first element is the data frame from the data.out option and the second element is the returns list.
On a side note, this is my first time using Github to contribute to a project, so please forgive any breaches of etiquette.
Hi Friend, Can you give an example using this feature? I'm trying to make it work using your branch but I can't. Thanks
Could you post the code you're trying to run and whatever outcome you get? Thanks.
Sure.
Code: data(iris) RStata::stata("sum Species", data.in = iris, returns.out=T)
Outcome: . sum Species
Variable | Obs Mean Std. Dev. Min Max
-------------+--------------------------------------------------------
Species | 150 2 .8192319 1 3
Erro: path
does not exist: ‘ReturnsToR.xls’
So it looks like it's having trouble with the import back into R. Can you confirm that you can bring the data back to R (data.out=T by itself) and what version of Stata you have?
data.out=T is working. My stata is version 13. Do you think I need to upgrade to work?
That's likely the issue. This was written in Stata 15 and they changed the syntax for the key function (putexcel) around Stata 14.2. I'll work on a solution to accommodate earlier Stata versions, but don't really have a work around for you right now.
I tried on stata 15, but there was another error:
Code: data (iris) names (iris) <- c ("a", "b", "c", "d", "e") RStata :: stata ("nlsur (d = {c1} + {c2} * e) variable (d e)", data.in = iris, returns.out = T)
Result: . nlsur (d = {c1} + {c2} * e) variable (d e) (obs = 150)
Calculating NLS estimates ... Iteration 0: residual SS = 7.359933 Iteration 1: residual SS = 7.359933 Calculating FGNLS estimates ... Iteration 0: scaled RSS = 150
Regression FGNLS
Equation | Obs Parms RMSE R-sq Constant
---------------- + --------------------------------- --------------------- 1 d | 150 2 .221509 0.9150 c1
d | Coef. Default To err. z P> | z | [95% Conf. Break]
------------- + ------------------------------------ ---------------------------- / c1 | -.5806667 .0478514 -12.13 0.000 -.6744537 -.4868796 / c2 | .89 .0221509 40.18 0.000 .846585 .933415
Error in .rowNamesDF <-
(x, value = value):
missing values in 'row.names' are not allowed
OK, I've pushed an update to accommodate the nslur output.
There is still no update if I try to install from your git. But there is no hurry, I try again in the future. Thanks for the support.
Apologies. Still getting the hang of using github, but I think it's pushed now. Give it a try and please let me know how it turns out.
Hi Friend. No problem, I am also learning these tools.
It's working now. I just couldn't find the p-value in the output list. Is it possible to extract this information from the list?
Thanks!
So the structure of the list will vary depending on what returns and ereturns the Stata call produces (so a lot of what is available depends on the whims of whomever is writing the Stata code). However, for most (all?) estimation commands, the output that is produced on the screen in Stata is stored in a return matrix.
So, for the nlsur command you mentioned above,
results <- RStata :: stata ("nlsur (d = {c1} + {c2} * e) variable (d e)", data.in = iris, returns.out = T)
the screen output table is going to be in results$Active$r$matrix$table and you can extract the pvalues from there.