Hemken / Statamarkdown

Functions to write Stata documentation with knitr
Other
59 stars 11 forks source link

using the output from stata in R #19

Closed aghaynes closed 1 year ago

aghaynes commented 3 years ago

Useful package...thanks! Is it possible to make the results from stata available to R for use in further processing downstream?

Stupid example, but say I have

```{stata}
summ var
```

and want to use r(mean) in other calculations in following R chunks

r(table) after regress and passing it to kable perhaps or some such would probably be a better example, but I'm sure you get the idea.

I guess the current solution would be similar to that proposed for inline results? Would be cool to be able to specify a (vector of?) outputs to pass from stata back to R...

On a slightly different note, maybe you can add a link to your ssc.wisc site the github repo... in the readme and/or in the repo settings. It's very useful, but not mentioned that I saw...

Hemken commented 1 year ago

You are right, it will take some method like I suggested for inline results. In the case of an r(table), you might use Stata's putexcel command, like

putexcel set filename.xlsx
matrix A = r(table)'
/*Note the apostrophe after r(table)!*/
putexcel A1 = matrix(A), names
putexcel save

followed by an R code chunk that reads the file and uses the results somehow.

I'll add an example to my documentation. And thanks for the suggestion to add a link here on Github to my website.