{smcl}
{cmd:help tvc_merge}
{hline}

{title:Title}
{cmd:tvc_merge} -- Merging files of time-varying covariates

{title:Syntax}

{p 8 17 2}
{cmd:tvc_merge} {it:startvar} {it:stopvar}{cmd:, }
{cmd:id(}{it:idvar}{cmd:)} 
[{cmd:failure(}{it:failvarlist}{cmd:)}
{cmd:merge(}{it:mergevar}{cmd:)}]

{title:Description}

{p 4 4 2} {cmd:tvc_merge} is intended for merging two files which
each contain time varying covariates. In other words, there are
several intervals for each subject in each file, with different
endpoints for the intervals in the different files. {cmd:tvc_merge}
will split overlapping intervals into separate disjoint
sub-intervals, so that each variable takes a single value throughout
the subinterval. Thus you will end up with more intervals in the
merged file, but the intervals will cover the same time period for
each subject.

{title:Options}

{phang}
{cmd:id} specifies the subject-id variable; {it:idvar} may be string
or numeric. 

{phang}
{cmd:failure} specifies the the variable(s) which consists of events
rather than exposures, or more generally any variables which only
take their values at the end of the time interval, rather than at
the beginning. If an interval needs to be split, the variables in 
{it:failvarlist} will take the value 0 in all subintervals except
the last, and whichever value they took in the dataset within the
final subinterval.

{phang}
{cmd:merge} specifies the name of a variable to be used to contain
information about whether there was information concerning the
relevant observation (i.e. time period from {it:startvar} to
{it:stopvar} for a given individual) in the master dataset
({it:mergevar} = 1), in the "using" dataset ({it:mergevar} = 2), or
both ({it:mergevar} = 3). This is optional since it is far less
relevant in this context than in a simple merge: there may be no
information in a given dataset because the individual had no events
of interest, not because the data was missing. 

{title:Remarks}

{pstd} 
{cmd:tvc_merge} assumes that the endpoints of the intervals are
different between the two files to be merged, and between different
individuals in each file. It was initially designed for a context in
which one file contained a series of time-varying exposures
(different drug treatments, which subjects could start and stop at
any time), and a second file consisted of a list of adverse events:
it was necessary to merge the data so as to find out which treatment
(if any) a subject was on when the adverse event occured. If the
endpoints are the same in each file, {cmd:merge id start } would be
sufficient to merge the files. If there are a small number of
endpoints that are consistent between individuals in a file,
{cmd:stsplit} could be used to split the intervals up as required.

{title:Also see}
{help stsplit}, {help merge}

{title:Author}

{pstd}
Mark Lunt, Arthritis Research UK Epidemiology Unit

{pstd}
The University of Manchester

{pstd}
Please email {browse "mailto:mark.lunt@manchester.ac.uk":mark.lunt@manchester.ac.uk} if you encounter problems with this program

