Announcement

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

  • Calculate lifetime number of events between birth and interview

    Hello,

    I have two datasets:

    1) Survey data with birth date info and interview date info
    2) ACLED data with conflict date

    I want to calculate the number of conflicts in a respondents life, but I am struggling with figuring out a way to do this.Any ideas?

    Basically, I need to link two datasets that do not share any commonalities, and this seems annoying in stata because I can't merge or append them.

    I need to create an empty conflict_events column in my survey data (conflict_events == 0), Then I need to like run a loop which is like if conflict_date. (in the other dataset) is between birth and interview date (both in the survey data), then add that to conflict_events column in the survey data? But I do not see how I can do that? Any tips would be appreciated! Thanks so much!

  • #2
    You are correct that you cannot accomplish this by -merge- or -append-. You could, in principle, do this using -cross- (see -help cross- if unfamiliar with it) to combine the two data sets and then use a -keep if....- command to retain only the pairings where the conflict_date falls between the birth date and interview date. However, the results of -cross- might be an extremely large dataset if either of your original data sets is substantial in size. An easier way to do this is with the -rangejoin- command, written by Robert Picard, and available from SSC. To use it, you must also install Robert Picard, Nick Cox, and Roberto Ferrer's -rangestat- command, also available from SSC.
    Code:
    use survey_data, clear
    rangejoin conflict_date birth_date interview_date using acled_data
    Replace all the italicized tokens with the actual data set and variable names. This will be faster than using -cross- and -keep if-, and it will be much less demanding of memory.

    Added:
    I need to link two datasets that do not share any commonalities, and this seems annoying in stata because I can't merge or append them.
    This seems to me a bit like being annoyed that your screwdriver is useless when you have to drive a nail. -merge- and -append- are just the wrong tools for the task at hand, and you just needed to discover the other tools in the Stata toolbox that work for this. That's what Statalist is for (not to mention other sources).
    Last edited by Clyde Schechter; 10 Dec 2023, 10:33.

    Comment


    • #3
      This worked! thanks so much for the rangestat tip, It is very handy. Really appreciate your help, Clyde!

      Comment

      Working...
      X