Code:
* Example generated by -dataex-. To install: ssc install dataex clear input str10 old_datec float old_date "01jan1960" 0 "15apr1960" 105 "30nov1960" 334 "20dec1960" 354 "09jun1981" 7830 "14feb1991" 11367 "15jul1972" 4579 "03aug1986" 9711 "28mar2018" 21271 end format %td old_date gen future_date = dofm(monthly(substr(old_datec, 3, 7), "MY") + 6) + day(old_date) - 1 format future_date %td gen delta = mofd(future_date) - mofd(old_date) assert delta == 6
Code:
old_datec old_date future_date delta 1. 01jan1960 01jan1960 01jul1960 6 2. 15apr1960 15apr1960 15oct1960 6 3. 30nov1960 30nov1960 30may1961 6 4. 20dec1960 20dec1960 20jun1961 6 5. 09jun1981 09jun1981 09dec1981 6 6. 14feb1991 14feb1991 14aug1991 6 7. 15jul1972 15jul1972 15jan1973 6 8. 03aug1986 03aug1986 03feb1987 6 9. 28mar2018 28mar2018 28sep2018 6
Is there a more direct way?
0 Response to Efficient ways to increment dates by given interval
Post a Comment