Skip to contents

Jan. 25, 2026

STATA users can use Rcall to run the functions from our R package fdid in STATA.

  1. Prerequisites:

    • Install the basic R into your machine.
      • In R, install our R package fdid by running the following code in console:
      install.packages("devtools")
      devtools::install_github("ccfang2/fdid")
    • Install the STATA package Rcall.
      • To check if you have successfully installed Rcall, you can type help rcall in STATA, and try out the small examples it has in the help file.

    In rare cases, when you encounter issues in installation, feel free to paste the errors into an AI chatbot (e.g., ChatGPT, Gemini) to see what it suggests. It often helps a lot.

  2. Once you have R, the R package fdid and Rcall successfully installed, you can run the whole example on the [Home] page in STATA via two different methods.

    • Use rcall script:
      • First, copy and paste the following code to create an R script file YourRScript.R, and save it to your working directory of your STATA.
      library(fdid)
      data(Gdata)
      Gdata$beta[,"event_t"] <- Gdata$beta[,"event_t"]- Gdata$t0 #Recenter the event time on 0
      
      # Classical Event Study Plot
      fdid_scb_est <- fdid_scb(beta=Gdata$beta, cov=Gdata$cov, t0=0)
      
      pdf("Classical_EventStudyPlot.pdf", width = 8, height = 6)
      par(cex.axis = 1.4, cex.lab = 1.4, cex.main = 1.4, family="Times")
      EventStudyPlot_Classical(fdid_scb_est, pos.legend="bottom", scale.legend=1.4)
      dev.off()
      
      # Simultaneous Confidence Bands
      pdf("SCB.pdf", width = 8, height = 6)
      par(cex.axis = 1.4, cex.lab = 1.4, cex.main = 1.4, family="Times")
      plot(fdid_scb_est, pos.legend="bottom", scale.legend=1.4, note.pre=FALSE, ci.post=TRUE)
      dev.off()
      
      # Honest Reference Band under Violation of No-anticipation Assumption
      pdf("SCB_NTA.pdf", width = 8, height = 6)
      par(cex.axis = 1.4, cex.lab = 1.4, cex.main = 1.4, family="Times")
      plot(fdid_scb_est, ta.ts=-2, ta.s=c(1.4,2.3), pos.legend="bottom", scale.legend=1.4, ci.post=TRUE, ref.band.pre = TRUE)
      dev.off()
      
      # Honest Reference Band under Violation of Parallel Trends Assumption
      pdf("SCB_PTA.pdf", width = 8, height = 6)
      par(cex.axis = 1.4, cex.lab = 1.4, cex.main = 1.4, family="Times")
      plot(fdid_scb_est, frmtr.m=c(0.25,0.25), pos.legend="bottom", scale.legend=1.4, ci.post=TRUE, ref.band.pre = TRUE)
      dev.off()
      • Second, run rcall script YourRScript.R in your STATA.
      • Last, you will see the plots saved in your working directory. You can change the size of your plots by playing with the arguments in pdf().
    • Use rcall: end:
      • First, copy and paste the following code to command line in STATA.
      rcall:
      library(fdid)
      data(Gdata)
      Gdata\$beta[, "event_t"] <- Gdata\$beta[, "event_t"] - Gdata\$t0
      fdid_scb_est <- fdid_scb(beta = Gdata\$beta, cov = Gdata\$cov, t0 = 0)
      par(cex.axis = 1.4, cex.lab = 1.4, cex.main = 1.4, family = "Times")
      EventStudyPlot_Classical(fdid_scb_est, pos.legend = "bottom",scale.legend = 1.4)
      end
      • Second, you will see teh event study plot saved in your working directory.
      • Third, you could generate other plots by changing the plot function above.

    Remark: rcall only allows us to call R functions in STATA, so you cannot generate the plots in an editable graphic window like those generated by the original STATA functions.

References

  1. Haghish, E. F. (2019). Seamless interactive language interfacing between R and Stata. The Stata Journal, 19(1), 61-82.