Dear All,
I have the following column containing year of observations:
Years go from 2000 to 2016. I would like to create a new variable "trend", which takes the value of 1 if year=2000; 2 if year=2001 and so on.
I tried a double loop:
However I do not get what I expected. I am making some mess with the two loops I guess. Any hint?
Thanks in advance
I have the following column containing year of observations:
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int year 2016 2011 2016 2012 2011 2002 2002 2001 2001 2016 2011 2008 2007 2005 2003 2003 2002 2013 2012 2011 2011 2004 2013 2012 2005 2002 2000 2013 2010 2005 2003 2005 2007 2004 2006 2006 2003 2009 2004 2009 2007 2006 2010 2008 2004 2000 2002 2008 2001 2010 2010 2006 2009 2006 2005 2008 2009 2008 2007 2004 2010 2016 2016 2015 2015 2015 2015 2015 2014 2014 2014 2014 2014 2013 2013 2012 2012 2009 2007 2003 2001 2001 2000 2000 2000 end
I tried a double loop:
Code:
gen trend=0 forval i=2000/2016{ forval n=1/17{ replace trend=`n' if year==`i' } }
Thanks in advance
Comment