Announcement

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

  • Matching election dates with transaction dates by distance

    Hello everyone,

    I am conducting research on volume of transactions around elections. I merged two datasets, one with the transactions and one with the elections for all the european countries. Within the merged dataset, I have 3 different date variables, date which is every single date between 1.1.2000 and 31.12.2019 (my sample period), edate which is the election date and transaction date. Within the merge, everything worked fine as the transactions were assigned to the correct country, but not to the closest election in that country (for example a transaction from 2002 has assigned the election date value for an election from 2019, even though there was an election in 2005 in that country). How can I make it so the edate for the transactions that have the wrong one are replaced with the date of the closest one for that country? Thank you for your time

  • #2
    I will be astonished if anybody can answer this question without seeing example data to work with. We don't know how you went about combining these different data sets, and there are several possibilities that are all consistent with the description you have given, but would require different approaches to solve your problem.

    Please post back showing example data that illustrates your problem. Be sure to use the -dataex- command to do that so that those who want to help you have sufficient information and can easily try working with the data. If you are running version 18, 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    I would actually recommend you post example data from each of the three data sets separately (choosing examples that include appropriate matching observations across the data sets). It may be that combining the data sets in a different way from how you did it might prove a better solution than working from your existing combination.

    Comment

    Working...
    X