خرید بک لینک

Vote count: 0

I have another Stata date question. I have two datasets, one with IDs and Dates. Here is the first dataset:

[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ID double Date float Date2
104203 18820 18820
104203 18950 18950
104203 19294 19294
104203 20001 20001
104203 18950     .
112589 17083 17083
112589 18684 18684
112589 19291 19291
112589 19292 19292
112589 19312 19312
112589 19752 19752
123712 18565 18565
123712 19207 19207
123712 19270 19270
123712 19303 19303
220348 19230 19230
220348 19278 19278
220348 19861 19861
227642 17065 17065
227642 17079 17079
end
format %td/dd/YY Date
format %td Date2
[/CODE]

The second dataset contains the same IDs and a date that lags the first one by 0-1000 days (but most are within 15 days):

[CODE]
* Example generated by -dataex-. To install: ssc install dataex
clear
input long ID float COMDATE2
112589 17994.756
112589 18686.793
112589  19753.74
112589         .
123712 19303.693
123712         .
123712         .
123712         .
220348 19278.777
220348         .
220348         .
220348         .
227642 17066.824
227642 17079.799
227642 17940.855
227642 17948.822
227642 18735.777
227642 19066.748
227642 20181.797
227642         .
end
format %td COMDATE2
[/CODE]

I want to merge the two files together. I've tried once, but the dates aren't aligning:

merge m:m ID using "C:filename",
gen lag = COMDATE2-Date2
bys ID: egen minimum_lag=min(lag)
gen Committment=lag if lag==minimum_lag & lag >=1000 
bys ID Date2(Committment) : keep if _n==1

I'm looking for a way to properly merge these two sets so that dates with the smallest lag time align.

asked 24 secs ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 4 خرداد 1395 ساعت: 4:13

صفحه بندی