Last active
January 9, 2018 15:10
-
-
Save btskinner/06fff323703e8f0c9d736543a8d0f03d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# make_data.R | |
Rscript make_data.R | |
# analysis.do | |
stata -b analysis.do | |
# graphics.R | |
Rscript graphics.R |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// analysis.do | |
// read data | |
insheet using "./data.csv", clear | |
// regress | |
reg y x1 x2 x3 | |
// output to variables | |
matrix output = r(table)' | |
drop _all | |
svmat output, n(col) | |
// names by hand b/c stata makes this all unreasonably difficult... | |
generate params = "" | |
replace params = "x" + string(_n) | |
replace params = "_cons" in 4 | |
// write to disk | |
outsheet using "./results.csv", comma replace |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## graphics.R | |
## read in results | |
res <- read.table('./results.csv', header = TRUE, sep = ',') | |
## coef plot | |
res$index = c(2:4,1) | |
pdf('./coefplot.pdf') | |
with(res, plot(b ~ index, ylim = c(-6,5), pch = 16, xaxt = 'n', ann = FALSE)) | |
with(res, segments(x0 = index, y0 = ll, x1 = index, y1 = ul)) | |
with(res, axis(1, at = 1:4, labels = c('_cons', paste0('x', 1:3)))) | |
with(res, abline(h = 0, lty = 2)) | |
dev.off() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## make_data.R | |
## vars | |
x1 <- rnorm(1000) | |
x2 <- rnorm(1000) | |
x3 <- rnorm(1000) | |
e <- rnorm(1000) | |
## structural eq | |
y <- 4 + 3 * x1 - 5 * x2 + 2 * x3 + 10 * e | |
## data frame | |
df <- data.frame(x1 = x1, x2 = x2, x3 = x3, y = y) | |
## write | |
write.table(df, './data.csv', quote = FALSE, sep = ',', row.names = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment