I generated a variable for year/month as below. The variable dt_fim corresponds to a date as YMD, but I just wanted to keep year and month in another variable.
How I am having trouble to get the year of this created variable (I have dropped the dt_fim variable). I tried both commands below but they brought
How can I get the year from variable anom_fim?
Code:
gen anom_fim = monthly(string(year(dt_fim))+" "+string(month(dt_fim)),"YM") format anom_fim %tm
Code:
anom_fim 2014m11 2014m11 2014m12 2014m12 2014m11
Code:
gen ano = year(anom_fim) anom_fim ano 2014m11 1961 2014m11 1961 2014m12 1961 2014m12 1961 2014m11 1961
Code:
gen ano2 = real(substr(string(anom_fim),1,4)) anom_fim ano2 2014m11 658 2014m11 658 2014m12 659 2014m12 659 2014m11 658
Comment