Stata Wrapper for the "paf" R package (Windows Version)

  • Description
  • This wrapper was developed for Stata users to use the "paf" R package in Stata for Windows. The "paf" package calculates the unadjusted/adjusted attributable fraction function of a set of covariates for a censored survival outcome from a Cox model using the method proposed by Chen, Lin and Zeng (2010).

  • Installation
    1. Install R software, which is freely available at http://cran.r-project.org.

    2. Type the commands install.packages("paf") in R Console to install the "paf" package.

    3. Type the commands install.packages("foreign") in R Console to install the "foreign" package.

    4. Save the Windows version of stata_wrapper.R file to your computer (make sure the extension of the file is .R).

  • Usage
  • To use this wrapper to calculate the attributable fraction function, type the following command in Stata: shell "...\Rscript" ...\stata_wrapper.R time='varible' status='variable' cov='covariate1,...' predictors='covariate1+covariate2+...' datafile='stata-data-set' resultfile='stata-data-set'

  • Examples
  • We will use a simulated dataset (test.dta) to illustrate the usage of the wrapper. The dataset includes the following variables. Suppose you have downloaded the dataset and the stata_wrapper.R file to the directory of "C:\\Stata", and your executable Rscript file is in the directory of "C:\Program Files\R\R-3.1.0\bin". Below are two examples of calculating attributable fraction functions.
    1. Calculate the unadjusted attributable fraciton function of x1: shell "C:\Program Files\R\R-3.1.0\bin\Rscript" C:\stata\stata_wrapper.R time='time' status='status' cov='x1' predictors='x1' datafile='C:\\Stata\\test.dta' resultfile='C:\\Stata\\results.dta'
    2. Calculate the attributable fraciton function of x1 adjusting for x2: shell "C:\Program Files\R\R-3.1.0\bin\Rscript" C:\stata\stata_wrapper.R time='time' status='status' cov='x1' predictors='x1+x2' datafile='C:\\Stata\\test.dta' resultfile='C:\\Stata\\results.dta'

  • Contact Information
  • lichenuky@uky.edu