Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Matching date intervals to dates across datasets

    Hello,

    I am working with two different datasets, one is a survey (dataset 1) that includes a date variable indicting when the respondent was interviewed. The other is a dataset of events that occurred (dataset2), with each event having an associated date.

    I would like to create a variable that records the number of events that occurred in the month prior to the individual's interview date. I have created an "interval window" with start and end date in the survey data file (dataset1). And I have read about the ssc command range join. However, I am not sure what variable I can use to actually match the observations across the datasets (what key variable to use). Unlike examples such as those elaborated on here, I dont have a key var similar across both.

  • #2
    There doesn't have to be a key variable to use -rangejoin-. The -by()- option is, well, optional. The -by()- option is used when you want to restrict the matches to require that some variable(s) found in both data sets match exactly. For example, if your data sets have geographic variation, with, say a region variable, and if you wanted to only match respondents from a given region with events in the same region, you would specify -by(region)- in your command. But if you have no such requirement, then there is no need for the -by()- option to be used.

    From your description, it sounds like the code you want is
    Code:
    use survey_data_set, clear
    rangejoin event_date interval_start_date interval_end_date using event_data_set

    Comment

    Working...
    X