Controlling for Time Trends—Add a Single t or a String of Year Dummies? How Should t Be Coded?
You are studying the effect of urbanization rate on household consumption. You use provincial panel data from 2000 to 2020. You run a regression:
1. Introduction: Your Y Is Naturally Growing Every Year—If You Don't Control for Time, the Coefficient on X May Be a Misunderstanding
You are studying the effect of urbanization rate on household consumption. You use provincial panel data from 2000 to 2020. You run a regression:
β̂₁ is significantly positive. You are about to conclude—"urbanization promotes consumption." Then you draw a graph—household consumption rose in almost all provinces between 2000 and 2020 (income was growing, the economy was developing), and the urbanization rate was also rising. These two "both rising" trends may be completely unrelated—your regression is merely capturing a spurious correlation between two variables' own independent time trends.
You need to control for "time" in your model. But how?
- Option A: Add a linear time trend variable ().
- Option B: Add a string of year dummy variables (, one 0/1 variable for each year).
In Stata, the operations differ by only a few characters—but the underlying assumptions and conclusions can be completely different.
Core message: A linear time trend (Option A) assumes that Y changes at a constant rate over time—each year that passes, Y increases by a fixed β_t units, regardless of business cycles, policy shocks, or external events. Year fixed effects (Option B) assume that each year has an independent time effect not constrained by any parametric form—2008 can deviate substantially from the linear trend between 2007 and 2009 because of the financial crisis. Option A consumes only 1 degree of freedom; Option B consumes T−1 degrees of freedom. If your T is large enough and the time effects may not be linear—year FE is safer and more flexible. If your T is small or you suspect that collinearity causes year FE to absorb most of the useful variation in X—a linear trend is more economical and interferes less with the identification of the core coefficient. The coding of t—what number you assign to each year—changes the meaning of the intercept and the interpretation of the coefficients: do you set t = 0 at the start year of the sample, the middle year, or some institutionally meaningful year? Different choices correspond to different 'time baselines.'"
2. Linear Time Trend t—A Straight Line Through Your Panel
2.1 Model Specification
where (or any equally spaced increasing values).
Meaning of β_t: After controlling for X, Y changes on average by β_t units each year. Regardless of what happened that year—financial crisis, policy shock, Olympics—the effect of time on Y is a constant β_t.
2.2 What a Linear Trend Does—It Eliminates the Spurious Correlation from "X and Y Both Growing Linearly Over Time"
Intuition: If you draw a straight line through all the years on a scatterplot of Y against X—time is "partialled out." After time is controlled for, you are comparing yourself with your neighbors (other provinces in the same year)—not comparing the 2020 you with the 2000 you.
Mathematically: A linear time trend is equivalent to removing a linear trend line from the time series of each variable, then regressing on the detrended residuals. If X and Y each have their own upward time trend, the detrending operation strips away the part that "grows naturally with the passage of time," leaving only the association between X and Y that transcends time.
2.3 How Should t Be Coded?—Not Just "1, 2, 3, ..."
Although the spacing of t (1 year, 1 quarter, 1 month) does not affect the estimate of β_t, the origin of t (which year corresponds to t = 0) affects the meaning of the intercept β₀.
Three common coding schemes:
| Coding Scheme | Example (Data 2000—2020) | Meaning of the Intercept β₀ |
|---|---|---|
| Natural coding | t = 2000, 2001, ..., 2020 | Predicted Y in year 0 AD (a meaningless extrapolation) |
| Starting from 1 | t = 1, 2, ..., 21 | Predicted Y one year before the sample exists (the year before the sample starts) |
| Centered | t = −10, −9, ..., 0, ..., 10 | Predicted Y at the middle year of the sample (a meaningful baseline) |
We strongly recommend using a centered t. Set t = 0 to correspond to the midpoint of the sample (or some institutionally/economically meaningful year, such as the year a policy was implemented). This way, the intercept β₀ equals "the predicted value of Y when X = 0 in the middle year of the sample"—a meaningful number within the sample range, not an absurd extrapolation to year 0 AD.
* Center at the sample midpoint
sum year
gen t = year - r(mean) // t = 0 corresponds to the average sample year
* Center at an institutional node (e.g., policy implementation year = 2010)
gen t = year - 20102.4 What a Linear Trend Assumes—And Where Problems Most Easily Arise
A linear trend assumes that the effect of time on Y is a straight line with a constant slope. But the real world is not linear. The difference between Y in 2008 and Y in 2007 may be completely different from the difference between 2018 and 2017. Financial crises, policy shocks, technological discontinuities—none of these are linear.
If you forcibly fit a linear trend to a nonlinear time effect, the unabsorbed nonlinear time fluctuations remain in the error term. If these fluctuations happen to be correlated with your X (for example, "in financial crisis years, urbanization investment also decreased"), your β₁ is still contaminated by time effects.
3. Year Fixed Effects—Each Year Gets Its Own Row
3.1 Model Specification
where is a set of T−1 year dummy variables (with the first year as the base group, or equivalently understood as each year having its own independent intercept).
In Stata:
reg y x i.year // Year FE (OLS)
xtreg y x i.year, fe // Equivalent to FE with year dummies
reghdfe y x, absorb(year) // High-dimensional FE, faster3.2 What Year FE Does—It Eliminates Any Time Effect Shared by All Individuals in Each Year
Year FE is equivalent to: within each year, subtracting the cross-sectional mean for that year from all variables (year-demeaning). Then regressing on the demeaned data.
This means: Any factor that affects all individuals simultaneously in a given year—nationwide economic expansions/recessions, nationwide policy changes, nationwide technological shocks—is absorbed by the year FE. The coefficient on your X is now identified solely from cross-sectional variation among different individuals within the same year.
Year FE does not assume that time effects take any particular functional form—they can be linear, nonlinear, jumpy, U-shaped, any shape. Each year independently "anchors" a level. This is the most important advantage of year FE over a linear trend.
3.3 The Cost—Degrees of Freedom + Potentially Absorbing Variation in X
- Loss of degrees of freedom: When T is large (e.g., daily data with T = 3650), year FE consumes T−1 = 3649 degrees of freedom—which may be prohibitively expensive. Usually, monthly or quarterly FE is used as a compromise, or a coarser time granularity.
- Absorption of variation: If your X varies mainly over time (e.g., a "nationwide policy" that changes only in certain years), year FE will absorb most or even all of the variation in X—your β₁ will be unidentified or have enormous standard errors. This is the classic dilemma of "policy variables + year FE"—year FE absorbs the time-varying component of the policy effect, which is precisely the source of identification for the policy.
4. Linear Trend vs. Year FE—How to Choose?
| Linear Time Trend t | Year Fixed Effects | |
|---|---|---|
| Assumption | Time effect is a straight line (constant rate of change) | Time effect is any shape (independent each year) |
| Number of parameters | 1 | T−1 |
| Degrees of freedom consumed | Very few | Many (be cautious when T is large) |
| Appropriate when | T is small (≤ 5), time effects approximately linear | T is large, time effects may be irregular |
| Source of identification | Uses both cross-sectional and time-series variation | Primarily cross-sectional variation (within year) |
| Cannot handle | Nonlinear time shocks | Nationwide policy variables (collinear with year FE) |
| Stata command | reg y x t |
reg y x i.year |
4.1 A Selection Framework
How large is your T?
├── T ≤ 5 → Linear trend (year FE consumes too many df)
├── 5 < T ≤ 15 → Year FE (the most common panel T range; df consumption is acceptable)
└── T > 15 → Year FE (but consider coarser time granularity, e.g., annual → two-year groups)
Could your time effects be nonlinear?
├── Yes (financial crises, policy discontinuities, etc.) → Year FE
└── No (steadily growing data) → A linear trend suffices
Is your X a "nationwide time-varying policy variable"?
├── Yes → Year FE will absorb the policy variation! → Use a linear trend + other strategies
└── No (X has cross-sectional variation across individuals) → Year FE is safer
4.2 They Can Coexist—Unit-Specific Linear Trends
A common hybrid strategy: year FE + unit-specific linear trends.
- absorbs annual shocks common to all units (nationwide business cycles, policies).
- allows each unit to have its own time trend. For example, when studying the effect of minimum wages on employment—different states may have had different employment growth trends before the policy was implemented. Unit-specific trends allow the fact that "the treatment group already had higher employment growth before the policy" to be absorbed—making the parallel trends assumption in DID more likely to hold.
In Stata:
* Unit-specific linear trends
xtreg y x i.year c.t##i.id // Too many interaction terms; not recommended
reghdfe y x, absorb(id year id#c.t) // Correct approach: reghdfeThe cost of unit-specific trends is substantial: you need to estimate a trend parameter for each unit (N additional parameters). Only use this strategy when N is not too large, T is sufficiently long, and there are theoretical reasons to believe that trends differ across units.
5. Common Pitfalls
5.1 Pitfall 1: Adding Year FE Solves Everything—Forgetting to Check the Source of Variation in X
Year FE removes all variation common to all individuals along the time dimension. If your X itself varies mainly over time and not across individuals (e.g., nationwide macroeconomic variables, uniformly implemented policies), year FE will absorb it together with the common time effects. After adding year FE, check whether the within-R² of X has plummeted to near zero—if so, your X lacks sufficient "cross-sectional variation across individuals," and year FE makes it unidentified.
5.2 Pitfall 2: A Linear Trend = "I Controlled for Time"—But Your Time Effects Are Not Linear
If your Y experienced a major fluctuation during the sample period (e.g., the 2008 financial crisis, the 2020 pandemic), a straight line cannot possibly capture such fluctuations. You have "controlled" for a time effect of the wrong shape—you are effectively claiming you have dealt with the time problem when in fact you have not. In the face of major fluctuations, year FE is the only honest choice.
5.3 Pitfall 3: Thinking That the Coding of t Affects β_t—It Doesn't, but It Affects β₀
Whether you use t = 1, 2, 3... or t = 2000, 2001, 2002..., the estimate of β_t is completely unchanged—because linear transformations do not change the slope. But the meaning of β₀ changes. Use a centered t (t = 0 at the sample midpoint or a meaningful year) to make the intercept interpretable—this is a widely recommended but frequently overlooked good practice.
5.4 Pitfall 4: In Panel Data, Using Both Unit FE and Year FE Means You Have "Controlled for All Time- and Unit-Level Confounders"
Unit FE eliminates all time-invariant unit heterogeneity. Year FE eliminates all time effects common to all units. But what neither can eliminate is—confounders that vary over time and differ across units (time-varying heterogeneity). For example, a firm hires an excellent CEO in a particular year—this change is time-varying and unit-specific; neither unit FE nor year FE can handle it. You still need control variables and an identification strategy to address this layer.
6. Summary
Five core takeaways on controlling for time trends:
-
A linear trend t = you assume the time effect is a straight line with a constant slope. It consumes only 1 degree of freedom, but any nonlinear time shock that deviates from the straight line remains in the error term and may continue to contaminate your coefficients.
-
Year FE = you assume the time effect can take any shape—each year has an independent intercept. It absorbs annual shocks common to all units, but consumes T−1 degrees of freedom and may absorb useful variation in X that "varies over time but not across individuals."
-
The coding of t—set t = 0 at the sample midpoint or an institutionally meaningful year. Do not let t = 0 correspond to year 0 AD or the year before the sample starts. Centering makes the intercept interpretable.
-
The choice depends on the size of T, the likely degree of nonlinearity in time effects, and the source of variation in X. T ≤ 5 → linear trend. T larger + possible nonlinear shocks → year FE. X is mainly a "nationwide time-varying variable" → linear trend (year FE would absorb the variation in X).
-
The two can coexist—year FE + unit-specific trends. The former absorbs common shocks; the latter allows trends to differ across units—but requires N not too large and T sufficiently long.
One-sentence conclusion:
"A linear time trend is a straight line—you assume that each year's effect on Y is exactly the same as the previous year's. Year fixed effects are a set of steps—you allow each year to jump to any height without needing to explain why. A straight line is 1 parameter and 1 assumption; a set of steps is T−1 parameters and 0 assumptions. When you cannot see the true shape of the time effect—steps are more honest than a straight line. But steps come at a cost—they block your view of any X that rises and falls together with those steps. Choosing between a line and steps is not about which is 'more correct'—it is about which allows your X to still be seen after controlling for time."
7. Presentation Suggestions for Bilibili / WeChat Official Account
- Bilibili video: Use "a straight line vs. a set of steps" as the core visual contrast. Opening: a panel scatterplot—X-axis is year (2000—2020), Y-axis is household consumption. Data points slope upward to the right overall. A straight line is drawn from 2000 to 2020 (linear trend). At 2008, the data points visibly collapse downward (financial crisis), but the straight line ignores it—it passes through the collapse impassively. Voiceover: "A linear trend assumes time is a straight line—the 'natural change' in Y is fixed every year. But 2008 was not an 'ordinary year'—your straight line cannot bend." The straight line peels away, replaced by a set of steps—one step per year, with the 2008 step visibly lower than the others. Voiceover: "Year fixed effects say: each year can jump to any height. 2008 can be lower, 2009 can be higher—I don't need to know why; I just don't let these annual fluctuations contaminate your β₁." Act 1 "How to code t": a timeline with a sliding origin. t = 0 at year 0 AD (off the edge of the frame, labeled "a meaningless intercept"), slide to t = 0 at the sample start year (labeled "intercept = predicted Y in the start year"), then slide to t = 0 at the sample midpoint (labeled "intercept = predicted Y in the middle year—the safest choice"). Voiceover: "The origin of t determines what the intercept is—set t = 0 at the middle of the sample, and you have a meaningful baseline within the sample range." Act 2 "How to choose": an animated decision tree—T ≤ 5 → linear trend (green light). T larger → ask "are there financial crises/policy discontinuities?" → yes → year FE (yellow light). Then ask "is X a nationwide time-varying policy?" → yes → linear trend (year FE will absorb your identifying variation—red light warning). Act 3 "They can coexist": the screen shows a panel with unit-specific trends—each unit has its own light-colored trend line, and all units share a set of year steps (dark-colored). Voiceover: "Year steps absorb nationwide common shocks—like 2008 when everyone did poorly. Unit-specific trend lines allow each province to have its own time slope—this province was growing faster than that one to begin with. Each does its own job—steps handle common time fluctuations, trends handle unit-specific time slopes."
- WeChat Official Account: A two-column comparison table of linear trend vs. year FE (assumptions, number of parameters, degrees of freedom consumed, source of identification, Stata commands) as the core infographic. The three coding schemes for t (natural coding, starting from 1, centered) with the meaning of the intercept, presented as three-row cards. The decision tree selection framework as a vertical flowchart. The equation and Stata command for unit-specific trends (
reghdfe, absorb(id year id#c.t)) as a code card. The four pitfalls (year FE absorbing X variation, linear trend not handling nonlinear shocks, t coding not affecting β_t but affecting β₀, FE+FE not handling time-varying heterogeneity) as warning cards. - Recommended titles:
- Main title: 《Controlling for Time Trends—Add a Single t or a String of Year Dummies?》
- Alternative title: 《Linear Trend vs. Year Fixed Effects—A Straight Line and a Set of Steps, Which Is More Honest?》
- New media title: 《Your Y Is Rising Every Year—If You Don't Control for Time, Your Coefficient on X May Just Be a Trend-Driven Spurious Correlation》
- Key quotes:
"A linear trend is a straight line—you assume each year's effect on Y is the same fixed rate. Year FE is a set of steps—you acknowledge that some years are just different, without needing to explain why. A straight line is more parsimonious; a set of steps is more honest."
"The origin of t is the anchor of your intercept. Set t = 0 at year 0 AD—your intercept is an absurd prediction of Y in year 0 AD. Set t = 0 at the sample midpoint—your intercept is 'the predicted value of Y when X = 0 in the middle year of your study period.' The same slope, different baselines—one is meaningful, the other is not."
"Year FE will absorb your X—if your X is a 'nationwide time-varying policy.' Year FE absorbs all time fluctuations shared by all provinces in each year—and those fluctuations happen to contain the variation in whether your policy was implemented. Before using year FE, ask yourself: does my X have enough cross-sectional variation?"
"Unit FE + year FE ≠ controlling for all confounders. What the two jointly capture is only the two fixed dimensions of time and units—confounders that vary over time and differ by unit remain in the error term and will still bias your β₁."