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

  • Description
  • This wrapper was developed for Stata users to use the "paf" R package in Stata for Mac. 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 Mac 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 R CMD BATCH '--args time="varible" status="variable" cov="covariate1,..." predictors="covariate1+covariate2+..." datafile="stata-data-set" resultfile="stata-data-set" ' .../stata_wrapper.R

  • 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 a folder named "~/Stata". Below are two examples of calculating attributable fraction functions.
    1. Calculate the unadjusted attributable fraciton function of x1: shell R CMD BATCH '--args time="time" status="status" cov="x1" predictors="x1" datafile="~/Stata/test.dta" resultfile="~/Stata/results.dta" ' ~/Stata/stata_wrapper.R
    2. Calculate the attributable fraciton function of x1 adjusting for x2: shell R CMD BATCH '--args time="time" status="status" cov="x1" predictors="x1+x2" datafile="~/Stata/test.dta" resultfile="~/Stata/results.dta" ' ~/Stata/stata_wrapper.R

  • Contact Information
  • lichenuky@uky.edu