We consider a recurrent events model with time-varying coefficients motivated by two clinical applications. We use a random effects (Gaussian frailty) model to describe the intensity of recurrent events. The model can accommodate both time-varying and time-constant coefficients. We use the penalized spline method to estimate the time-varying coefficients. We use Laplace approximation to evaluate the penalized likelihood without a closed form. We estimate the smoothing parameters in a similar way to variance components. We conduct simulations to evaluate the performance of the estimates for both time-varying and time-independent coefficients. We apply this method to analyze two data sets: a stroke study and a child wheeze study. Copyright © 2012 John Wiley & Sons, Ltd.