Teach Yourself TVEM

How to use the TVEM Learning Path

simulated TVEM graphicThe text, videos, links, and SAS code below are designed to allow SAS users to teach themselves how to plan, prepare data for, and run a time-varying effect model (TVEM). This page is designed for users of all levels to be able to jump in wherever they need information. Within each section, there may be different ways to get the same information (e.g., watching a video, listening to a podcast, or running a SAS exercise). Users who possess basic familiarity with a given subject may want to download and run SAS code immediately. Users who are new to a subject may want to watch a video before running the relevant code.

All materials are designed for researchers who are new to TVEM but who do have some familiarity with SAS. In other words, this is a TVEM tutorial, not a SAS tutorial.

If you want to follow along with the examples below, you will need a computer that runs Windows with an installation of SAS 9.2 or higher. You will also need to download the %TVEM SAS macro or, for some advanced exercises, the %WeightedTVEM SAS macro.

Conceptual Introduction to TVEM

TVEM is an extension of linear regression that allows the association between two variables to be modeled without making assumptions about the nature of the association. For example, TVEM does not force an estimated curve to be linear. TVEM can be applied to cross-sectional data, panel data, or intensive longitudinal data. The Methodology Center maintains a number of resources for introducing TVEM.

video: Overview (9 minutes)
pptx: Introduction to Time-Varying Effects Models (TVEM) (part of the TVEM Teachers’ Corner instructional download)
pptx: Questions TVEM can answer (subset of the slideshow above)

webpage: Conceptual introduction to TVEM for intensive longitudinal data

Detailed Introduction

If you have a conceptual understanding of what TVEM is, you may want a more comprehensive understanding of TVEM’s applications and capabilities before you apply TVEM to your data.

video: Workshop with Stephanie Lanza (2 hours)
articles: Recommended publications to introduce TVEM
webpage: Data characteristics appropriate for TVEM
webpage: Intensive longitudinal data example on smoking cessation

webpage: Panel data example on predicting risky sexual behavior 
webpage: TVEM FAQ High-interest FAQ: What is ‘Time’ in TVEM?
podcast: Getting started with TVEM (25 minutes)

Running a SAS Macro

This video explains how to include and call a SAS macro. Section 4.1 of the %TVEM SAS Macro Users’ Guide includes text about these steps.

There are three basic steps needed before you can run a Methodology Center SAS macro.

If you haven’t already done so, download the %TVEM macro and save the macro to the designated path (e.g., S:myfolder).

Direct SAS to read the macro code from the path, using a SAS %INCLUDE statement, such as, “%INCLUDE ‘S:myfolder\TVEM_v311.sas’;” Note: we suppose that the SAS macro file exists in the folder S:myfolder. This path represents any user-specified folder. This convention will be followed in the examples and the appendices.

Use a libname statement to direct SAS to the data file. The statement should give the libname command, name the library, and then identify the path to the data. For example, libname sasf ‘s:myfolder’;

Flipping Data from Long to Wide Format

This brief section explains how to convert data from wide format (i.e., one row per subject) to long format (i.e, one row per observation). This is needed primarily in cases where TVEM is being used on intensive longitudinal data (ILD).

Data are often stored such that each observation is a separate column in the data base. To run TVEM, data must be organized so that there is a separate row for each observation. Thus, if a subject has multiple observations, that individual will have multiple rows in the data set.

Download this SAS code FlippingData_Wide_to_Long.sas to run the example in the video. (Note: you do not need to watch the video to run the code.)

Preparing to Run a TVEM

This video is largely conceptual. Topics addressed are listed by time-marker.

00:00 Do you have a question about time-varying effects?

00:34 Is TVEM appropriate for your data? Read a webpage that lists the data characteristics needed for TVEM.

1:09 Checking for large gaps in your measure of time.

2:08 Data must share a meaningful zero point.

3:42 Which covariates do you want to explore for time-varying effects? Short answer: if you’re not sure, model a covariate as both time-varying and non-time-varying and check the AIC and BIC.

5:23 Adding an intercept to your data.

Download this SAS code preparing.sas and this data set nointercept.sas7bdat to run the example in the video. (Note: you do not need to watch the video to run the code.)

Running a TVEM

This video describes the steps for running the %TVEM SAS macro. To run the exercise in this video, first download the macro and users’ guide. Then, download this SAS code running_a_tvem.sas and this data set simaddhealth.sas7bdat. (Note: you do not need to watch the video to run the code.)

There is a separate macro for running a weighted TVEM, but users are strongly encouraged to understand the %TVEM SAS macro before using the %WeightedTVEM SAS macro.

Steps covered include:

00:36 reading in a data set

01:57 including the macro in SAS

02:46 running an intercept-only model (code description, how to run, and output)

 For a text description of the code, see section 4.3 of the users’ guide (PDF).

Plotting Results from a TVEM

These videos describe how to plot and interpret the output from the TVEM SAS macro. This video continues the example from the “Running a TVEM” section, above. If you have not already done so, download the macro and users’ guide. Then, download this SAS code running_a_tvem.sas and this data set simaddhealth.sas7bdat. (Note: you do not need to watch the video to run the code.) 

Video 1 describes the output and intercept-only TVEM plots. Video 2 describes TVEM plots with a time-varying effect.

This is the last step in the learning path for TVEM. The next step is for a different (though related) macro. Congratulations on completing the path.

Running the Weighted TVEM Macro

This video describes how to use the %WeightedTVEM SAS macro. To run the exercise in this video, download the macro and the users’ guide. Then download this SAS code weighted_tvem_example.sas. The analysis uses the same simaddhealth.sas7bdat data set as the previous exercises. (Note: you do not need to watch the video to run the code.) 

Last updated: May 11, 2020