T. Lai and D. Small: Marginal Regression Analysis of Longitudinal Data with Time-Dependent Covariates. The file 'rprograms_timedependcov.R' contains R functions that use two-step GMM to fit a linear model with time-dependent covariates. The functions assume that each unit is observed for T time periods. The data should be arranged into three matrices ymat, xmat, zmat, where ymat is an NxT matrix containing the outcome, with each unit's outcomes at times 1,..., T in a row; xmat is an Nx(T*number of time dependent covariates) matrix, with the rows arranged as first time dependent covariate for times 1,...,T for the unit, second time dependent covariate for times 1,...,T for the unit, ..., last time dependent covariate for times 1,...,T for the unit; zmat is an Nx(number of time-independent covariates), with each unit's time-independent covariates arranged in a row. The functions assume that an intercept is to be included in the model; the intercept should not be included in the time independent covariates. To fit a two-step GMM model, the user must first classify the types of the time-dependent covariates (the function only allows Type 2 or Type 3) and use the function validmomcondticovfunc to specify which moment conditions will be considered. Then the user fits the two-step GMM model with the specified moment conditions using the function twostepgmmticovfunc. The other functions in the file need to be read into R in order for the function twostepgmmticovfunc to work. The function twostepgmmticovfunc outputs a list with three values: betahat: the coefficient vector -- the ordering of the coefficients is the intercept, the time- dependent coefficients and the time-independent coefficients. gmmobjmin: The value of the GMM objective function, i.e., Q_N(beta) in the paper asycovest: the estimated covariance matrix of the estimates Example: Suppose T=5 and there are 3 time-dependent covariates and 2-time-independent covariates, and the 3 time-dependent covariates are classified as Type 2, Type 3 and Type 2. We would fit the model by: momsel=validmomcondticovfunc(5,c(1,0,1),2) modelfit=twostepgmmticovfunc(ymat,xmat,zmat,momsel) For more information, please contact: Dylan Small Department of Statistics The Wharton School, University of Pennsylvania 400 Huntsman Hall, 3730 Walnut St. Philadelphia, PA 19104 e-mail: dsmall@wharton.upenn.edu