Quantcast
Channel: Statalist
Viewing all articles
Browse latest Browse all 73287

Panel data: Replace missing values id it happend between dates

$
0
0
Hello,

I have a panel data-set that I am in the process of cleaning. This data-set records violent incidents of patients in a mental health clinic. A patient can have different admissions and admissions can have multiple violent incidents. Admission ID also have its corresponding admission date.

I need to fix missing values for the admission Id and the Admission date. I can deduce the admission ID and Date by looking at previous and post incidents and the admission date variable. For example patient 2, have a missing admission ID and date for incident 9, but incident 9 happened between between 11/13/13 and 9/21/14, and these two date have the same admission date. Therefore incident 9 should be assigned admission id 51 and its corresponding admission date 9/1/2010.

For patient ID 1 there is no way to tell what is the correct value for missing value so it should remain as missing.
Patient_ID Admission_ID Incident_ID Incident_Date Admission_Date
1 1 10/4/2013
1 10 2 3/22/2014 11/7/2010 17:16
2 51 3 1/3/2013 9/1/2010 17:32
2 51 4 3/13/2013 9/1/2010 17:32
2 51 5 7/19/2013 9/1/2010 17:32
2 51 6 9/6/2013 9/1/2010 17:32
2 51 7 10/20/2013 9/1/2010 17:32
2 51 8 11/13/2013 9/1/2010 17:32
2 9 2/7/2014
2 51 10 9/21/2014 9/1/2010 17:32
2 5 11 9/27/2014 9/1/2010 17:32
2 51 12 4/29/2015 9/1/2010 17:32
2 51 13 9/26/2015 9/1/2010 17:32

Below you can find a dataex sample.


Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input byte(patient_id admission_id incident_id) double(incident_date_t admission_date_t)
1  .  1 19635             .
1 10  2 19804 1604769360000
2 51  3 19361 1598981520000
2 51  4 19430 1598981520000
2 51  5 19558 1598981520000
2 51  6 19607 1598981520000
2 51  7 19651 1598981520000
2 51  8 19675 1598981520000
2  .  9 19761             .
2 51 10 19987 1598981520000
2  5 11 19993 1598981520000
2 51 12 20207 1598981520000
2 51 13 20357 1598981520000
4 55 17 19283 1.6640664e+12
4 55 18 19289 1.6640664e+12
4 55 19 19289 1.6640664e+12
4 60 20 19563 1673448720000
4 61 21 19738 1698539280000
4  . 22 19743             .
4 61 23 19749 1698539280000
end
format %td incident_date_t
format %tc admission_date_t

Thank you,
Marvin

Viewing all articles
Browse latest Browse all 73287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>