Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • product of county fixed effects and trend

    Dear All, Suppose that I have the data
    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
    where county_fips denotes the county code. My question is how to simplify the following, if possible?
    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'
    }
    Any suggestion is highly appreciated.
    Ho-Chuan (River) Huang
    Stata 19.0, MP(4)

  • #2
    All I can say is that I cannot imagine an analysis where the creation of all the separate variables would be of use.
    Simply:
    Code:
    bys county (year): gen trend=_n
    gen trendsq = trend^2
    is probably going to be a more useful approach in most cases

    Comment


    • #3
      Hi, Jorrit,
      1. Thanks for the reply. But this is not what I had in mind.
      2. In fact, the code was taken from a published paper (https://onlinelibrary.wiley.com/doi/...111/ecoj.12451) in Economic Journal (a top-tier Journal in economics). The authors tried to control for the so-called county (county_fips) linear trend effect.
      3. Any other suggestion would be appreciated.
      Ho-Chuan (River) Huang
      Stata 19.0, MP(4)

      Comment


      • #4
        Well, the study highlights the use of panel data methods to analyze a problem that has been studied with non-panel methods, but the authors do not use any of the xt suite available in Stata. Had they done that, the creation of all the separate variables would not have been needed.

        Comment

        Working...
        X