-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvertCMC.ado
36 lines (36 loc) · 978 Bytes
/
convertCMC.ado
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
*! version 2.1 30sep2019
*
* convertCMC
*
* Converts CMC dates (i.e. months since the start of the year
* 1900) into Stata dates, randomly imputing day of the month
*
* Author: Ian Timaeus, LSHTM ([email protected])
* Initiated: 7-Mar-2015
*
program define convertCMC
version 10
syntax varlist(min=1 numeric)
tokenize `varlist'
quietly {
tempvar yr mo dcm maxd
gen int `yr' = .
gen byte `mo' = .
gen byte `dcm' = .
gen byte `maxd' = .
}
quietly while "`1'" != "" {
local cmc_date `1'
local s_date `1'
* calculate the components of the date
replace `yr' = 1900 + int((`cmc_date' - 1) /12)
replace `mo' = `cmc_date' - 12*(`yr' - 1900)
replace `dcm' = `mo'==12
replace `maxd' = day(mdy(cond(`dcm',1,`mo'+1),1,`yr'+`dcm')-1)
recast long `s_date'
replace `s_date' = mdy(`mo', floor(1+`maxd'*uniform()), `yr')
* assign default date format to Stata date variables
format `s_date' %td
macro shift
}
end