如何从非日期格式的字符串变量中提取日期?
How to Extract Date Out of a String Variable that is not in Date Format?
我想从字符串变量中提取日期。但是字符串变量看起来一点也不像传统的日期格式。
我的数据集是这样的:
v1 date
234 nominal_price_2010
545 nominal_price_2011
23 nominal_price_2012
934 nominal_price_2013
我想得到什么:
v1 date
234 2010
545 2011
23 2012
934 2013
解决方案 1:
destring date, ignore("nomial_prce") replace
解决方案 2:
gen work = real(substr(date, -4, 4))
drop date
rename work date
我想从字符串变量中提取日期。但是字符串变量看起来一点也不像传统的日期格式。
我的数据集是这样的:
v1 date
234 nominal_price_2010
545 nominal_price_2011
23 nominal_price_2012
934 nominal_price_2013
我想得到什么:
v1 date
234 2010
545 2011
23 2012
934 2013
解决方案 1:
destring date, ignore("nomial_prce") replace
解决方案 2:
gen work = real(substr(date, -4, 4))
drop date
rename work date