Dear All, Suppose that I have the data
where county_fips denotes the county code. My question is how to simplify the following, if possible?
Any suggestion is highly appreciated.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input double county_fips float year 1 1977 1 1978 1 1979 1 1980 1 1981 1 1982 1 1983 1 1984 1 1985 1 1986 1 1987 1 1988 1 1989 1 1990 1 1991 1 1992 1 1993 1 1994 1 1995 1 1996 1 1997 1 1998 1 1999 1 2000 1 2001 1 2002 1 2003 1 2004 1 2005 1 2006 1 2007 1 2008 1 2009 1 2010 1 2011 3 1977 3 1978 3 1979 3 1980 3 1981 3 1982 3 1983 3 1984 3 1985 3 1986 3 1987 3 1988 3 1989 3 1990 3 1991 3 1992 3 1993 3 1994 3 1995 3 1996 3 1997 3 1998 3 1999 3 2000 3 2001 3 2002 3 2003 3 2004 3 2005 3 2006 3 2007 3 2008 3 2009 3 2010 3 2011 end
Code:
* Generate county-specific trends to be used in the regression analyses bys county (year): gen trend = _n quietly tabulate county_fips, gen(county_FE_) foreach var of varlist county_FE* { gen `var'_trend = `var'*trend drop `var' } gen trend_sq = trend^2 quietly tabulate county_fips, generate(county_fe_) foreach var of varlist county_fe* { gen `var'_trend_sq = `var'*trend_sq drop `var' }
Comment