stata如何计算两个日期之间的月份
How to calculate month between two dates in stata
我想用信用年龄创建一个变量。数据只有信用开始日期。
我为默认值创建日期变量(例如 2017-12-31)。然后,我想用开始学分的日期计算年龄。
我试图搜索有关该内容的文章,但没有成功。
谢谢。
你的数据好像是每天的。在这种情况下,您需要的是:
gen current_date=date("20171231","YMD")
format current_date %td //this will be the variable from which age will be calculated
gen age=current_date-start_credit_date //again, assuming the start credit variable is daily
这给出了年龄变量作为天数。如果你想要它作为月数,你需要添加:
gen current_month=mofd(current_date)
format current_month %tm
gen start_month=mofd(start_credit_date)
format start_month %tm
gen age_month=current_month-start_month
我想用信用年龄创建一个变量。数据只有信用开始日期。
我为默认值创建日期变量(例如 2017-12-31)。然后,我想用开始学分的日期计算年龄。
我试图搜索有关该内容的文章,但没有成功。
谢谢。
你的数据好像是每天的。在这种情况下,您需要的是:
gen current_date=date("20171231","YMD")
format current_date %td //this will be the variable from which age will be calculated
gen age=current_date-start_credit_date //again, assuming the start credit variable is daily
这给出了年龄变量作为天数。如果你想要它作为月数,你需要添加:
gen current_month=mofd(current_date)
format current_month %tm
gen start_month=mofd(start_credit_date)
format start_month %tm
gen age_month=current_month-start_month