想要得到年份的变量和月份的变量
1.如果原变量是日期变量,则可:
gen year=year(Variable) //生成年份变量year
gen month=month(Variable) //生成月份变量month
2.如果原变量是文本变量(格式具体为:2007/05),则可:
gen year=substr(dat1,1,4) //生成年份变量year,字符型
gen month=substr(dat1,6,2) //生成月份变量month,字符型
若要的是数值型,则再:
destring year month,replace