Dummy Variables as Explanatory Regressors: Intercept Shifts, Interactions & Nested Testing

Econometrics Exercise #9b

Author

Ahmed Mustafa

Published

December 3, 2026

Show R code
:root {
  --brand: #AA272F;
  --brand-dark: #7F1D24;
  --brand-pale: #F7E9EA;
  --brand-blue: #1B4F72;
  --brand-green: #477A63;
  --brand-amber: #B7791F;
  --ink: #292929;
}
body { color: var(--ink); line-height: 1.6; }
h1, h2, h3 { color: var(--brand-dark); }
h1 { border-bottom: 2px solid var(--brand); padding-bottom: .25rem; margin-top: 2.4rem; }
h1.title { border-bottom: none; color: var(--brand); font-weight: 800; }
p.subtitle { color: var(--brand-blue); font-weight: 500; }
.callout-note      { border-left-color: var(--brand) !important; }
.callout-tip       { border-left-color: var(--brand-green) !important; }
.callout-warning   { border-left-color: var(--brand-amber) !important; }
.callout-important { border-left-color: var(--brand-blue) !important; }
table caption { color: var(--brand-dark); font-weight: 700; }
table thead th { background: var(--brand-dark) !important; color: #fff !important; }
.table > tbody > tr:nth-of-type(odd) > * { background-color: #FBF5F5; }

/* Headline scorecards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
             gap: .9rem; margin: 1.2rem 0 1.6rem; }
.stat-card { border: 1px solid #E7D3D5; border-top: 5px solid var(--brand); border-radius: 6px;
             padding: .75rem 1rem .8rem; background: #fff; box-shadow: 0 2px 6px rgba(41,41,41,.07); }
.stat-card.blue  { border-top-color: var(--brand-blue); }
.stat-card.green { border-top-color: var(--brand-green); }
.stat-card.amber { border-top-color: var(--brand-amber); }
.stat-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: #6b6b6b; font-weight: 700; }
.stat-value { font-size: 1.85rem; font-weight: 800; color: var(--brand-dark); line-height: 1.15; margin: .15rem 0 .2rem; }
.stat-note  { font-size: .84rem; color: #444; line-height: 1.35; }

/* Reader legend */
.legend-row { display: flex; gap: .7rem; align-items: baseline; margin: .35rem 0; }
.chip { display: inline-block; min-width: 11.5rem; padding: .15rem .6rem; border-radius: 4px; color: #fff;
        font-weight: 700; font-size: .85rem; text-align: center; }
.chip.tip  { background: var(--brand-green); }
.chip.note { background: var(--brand); }
.chip.warn { background: var(--brand-amber); }
.chip.imp  { background: var(--brand-blue); }

60-second version

Raw gap in averages
+0.64 pp
High-FDI vs Low-FDI years, no controls (p = 0.854)
Gap at the same GDP
+3.62 pp
Model 2 dummy: High-FDI years vs Low-FDI years of equal GDP (p = 0.045)
Do GDP slopes differ?
p = 0.251
Model 4 extra-slope test: no clear evidence that the GDP effect changes with the FDI regime
Best-fitting model
M5
Two dummies (FDI + trade) (lowest BIC; adjusted R² = 0.83)
TipSummary
  • Raw averages. Years with above-median FDI had a renewable share only 0.64 percentage points (pp) higher than other years (p = 0.854): practically no difference.
  • Holding GDP fixed changes the picture. Comparing years of the same GDP, High-FDI years sit 3.62 pp higher (p = 0.045, moderate evidence). Raw averages hide part of the gap because High-FDI years were also richer years (about 8.9% higher GDP on average), and that GDP difference alone moves the renewable share by −2.98 pp, which cancels part of the FDI gap.
  • FDI regimes do not clearly change how GDP matters. The test that the two regimes have different GDP slopes gives p = 0.251 (no clear evidence).
  • Trade openness matters more. Adding a High-trade dummy puts High-trade years 5.55 pp higher (p = 0.002), changes the FDI gap to 2.61 pp (p = 0.080), and gives the best-fitting model (M5).
  • How far to trust it: the trade-regime result survives a robustness check for autocorrelated errors, and the FDI-regime result is rated “fragile” (see Section 6). All results are associations in 27 annual observations, not causal effects.

1 How to read this document

ImportantFour kinds of boxes, one idea each
In Simple TermsThe idea in in simple terms.
What the numbers sayEvery number in the table above it, translated into units you can picture.
CarefulWhy the number might mislead you.
VerdictThe decision, in one or two sentences.

pp means percentage points of renewable share (for example, going from 60% to 63% is +3 pp). Rows in bold in a coefficient table have p < 0.05.

Term Meaning
Dummy variable A yes/no switch: 1 for the years in a group, 0 for all other years
Reference group The group the switch is compared against (here the Low-FDI years)
Level shift (intercept shift) The whole line moves up or down
Tilt (slope shift, interaction) The line rotates: GDP matters differently in the two groups
Nested models and F-test A simple model vs the same model plus extra terms. The F-test asks: did the extras earn their place?
AIC, BIC Fit scores that charge a fee for every extra term. Lower is better. BIC charges more
HAC standard errors An honest margin of error for data where each year resembles the previous year
WarningGround rules that apply to every result below
  • Association, not causation. The groups are drawn by the analyst from Sudan’s own sample (a median split, not an official classification, and not a randomised treatment).
  • One country, 27 annual observations (1995–2021). Small samples give tests low power: “not significant” never means “no effect”.
  • Years are not independent. Section 6 checks what this does to the p-values.
  • Course convention: the matrix of regressors is treated as fixed (deterministic).

2 Meet the data

2.1 The sample

Show R code
data.frame(
  Item = c("Country", "Workspace source", "Period", "Complete annual observations (N)",
           "Outcome (y)", "Regressor", "Year information"),
  Value = c("Sudan (SDN)", data_source, paste(year_lo, year_hi, sep = "–"), N_obs,
            "REN_ERG_CONS: renewable energy, % of final energy consumption",
            "logGDP: natural log of GDP in billion USD, centred (see Step 0 below)", year_note)
) |> brand_table("Sample used in every model of this exercise")
Sample used in every model of this exercise
Item Value
Country Sudan (SDN)
Workspace source pamat_cvicenie9.Rdata (object: udaje9)
Period 1995–2021
Complete annual observations (N) 27
Outcome (y) REN_ERG_CONS: renewable energy, % of final energy consumption
Regressor logGDP: natural log of GDP in billion USD, centred (see Step 0 below)
Year information Year restored from LDC-Panel-Data.csv (rows matched one-to-one)
NoteWhat the numbers say

All six models use exactly the same 27 years, so their F-tests and their AIC/BIC scores are comparable. Sudan’s GDP in this sample runs from about USD 26.2 bn to USD 59.2 bn, with a typical (geometric-mean) value of about USD 46.0 bn. The renewable share starts at 81.5% in 1995 and ends at 61.0% in 2021.

2.2 The dummy-variable toolbox in one picture

TipIn Simple Terms

A dummy variable lets two groups of years share one regression but follow their own rules. There are four possible categories. The six models in this document are simply ways of asking which category Sudan belongs to. (The lines below are an illustration, not Sudan’s data.)

Show R code
x <- seq(-1, 1, length.out = 40)
mk <- function(panel, f_low, f_high) {
  rbind(data.frame(panel = panel, x = x, y = f_low(x),  grp = "Low-FDI years"),
        data.frame(panel = panel, x = x, y = f_high(x), grp = "High-FDI years"))
}
toy <- rbind(
  mk("A. One common line\n(regime does not matter)", function(x) -x, function(x) -x),
  mk("B. Parallel lines\n(level shifts)",             function(x) -x, function(x) -x + 0.9),
  mk("C. Same start, new tilt\n(slope shifts)",       function(x) -x, function(x) -0.2 * x),
  mk("D. Level and tilt differ\n(full interaction)",  function(x) -x, function(x) 0.6 - 0.2 * x))
toy$panel <- factor(toy$panel, levels = unique(toy$panel))
ggplot(toy, aes(x, y, colour = grp, linetype = grp, linewidth = grp)) +
  geom_line() +
  facet_wrap(~ panel, nrow = 1) +
  scale_colour_manual(values = c("Low-FDI years" = brand_blue, "High-FDI years" = brand), name = NULL) +
  scale_linetype_manual(values = c("Low-FDI years" = "solid", "High-FDI years" = "22"), name = NULL) +
  scale_linewidth_manual(values = c("Low-FDI years" = 1.8, "High-FDI years" = 1.0), name = NULL) +
  labs(x = "GDP  →", y = "Renewable share  →") +
  theme_brand() +
  theme(axis.text = element_blank(), panel.grid = element_blank())
Figure 1: The four possible categories for two groups of years (illustration only).
Model The question it asks Category
M1 Is one common line enough for all years? A
M2 At the same GDP, do High-FDI years sit higher or lower? B
M3 Do the two lines share a starting point but tilt differently? C
M4 Can both level and tilt differ? D
M5 Does a second switch (trade openness) add anything beyond FDI? B (two switches)
M6 Does industry’s share of GDP (three groups) shift the line? B (three groups)

2.3 How Sudan’s years are split into regimes

Show R code
tier_n <- table(df_clean$IndTier)
thr <- data.frame(
  `Dummy` = c("D1: High-FDI year", "D2: High-trade year", "Industry tier: Medium", "Industry tier: High"),
  `Rule (a year counts as 1 when ...)` = c(
    paste0("FDI_GDP > ", f2(med_fdi), " % of GDP (sample median; a tie counts as Low)"),
    paste0("Trade_GDP > ", f2(med_trade), " % of GDP (sample median)"),
    paste0(f2(tertiles_ind[1]), " < IND_VA_GDP ≤ ", f2(tertiles_ind[2]), " % of GDP (middle third)"),
    paste0("IND_VA_GDP > ", f2(tertiles_ind[2]), " % of GDP (top third)")),
  `Reference group` = c("Low-FDI years", "Low-trade years", "Low-industry years", "Low-industry years"),
  `Years coded 0 / 1` = c(
    paste(table(df_clean$HighFDI), collapse = " / "), paste(table(df_clean$HighTrade), collapse = " / "),
    paste(nrow(df_clean) - tier_n[["Medium"]], "/", tier_n[["Medium"]]),
    paste(nrow(df_clean) - tier_n[["High"]], "/", tier_n[["High"]])),
  `Which years` = c(year_ranges(df_clean$Year[df_clean$HighFDI == 1]),
                    year_ranges(df_clean$Year[df_clean$HighTrade == 1]),
                    year_ranges(df_clean$Year[df_clean$IndTier == "Medium"]),
                    year_ranges(df_clean$Year[df_clean$IndTier == "High"])),
  check.names = FALSE)
brand_table(thr, "How the regimes are defined, and which years fall into each")
Table 1: How the regimes are defined, and which years fall into each
Dummy Rule (a year counts as 1 when ...) Reference group Years coded 0 / 1 Which years
D1: High-FDI year FDI_GDP > 3.30 % of GDP (sample median; a tie counts as Low) Low-FDI years 14 / 13 1999, 2001–2006, 2009–2010, 2012–2013, 2015, 2018
D2: High-trade year Trade_GDP > 24.71 % of GDP (sample median) Low-trade years 14 / 13 2000, 2002–2011, 2013, 2019
Industry tier: Medium 18.77 < IND_VA_GDP ≤ 21.21 % of GDP (middle third) Low-industry years 18 / 9 2000–2003, 2010–2013, 2018
Industry tier: High IND_VA_GDP > 21.21 % of GDP (top third) Low-industry years 18 / 9 2004–2009, 2019–2021
Show R code
pal_fdi <- c("Low-FDI year" = brand_blue, "High-FDI year" = brand)
p_a <- ggplot(df_clean, aes(Year, REN_ERG_CONS)) +
  geom_line(colour = "grey75") +
  geom_point(aes(colour = FDI_Group), size = 3) +
  scale_colour_manual(values = pal_fdi, name = NULL) +
  labs(title = "Renewable share of energy use", x = NULL, y = "% of final energy") + theme_brand()
p_b <- ggplot(df_clean, aes(Year, FDI_GDP, fill = FDI_Group)) +
  geom_col(width = 0.75) +
  geom_hline(yintercept = med_fdi, linetype = "dashed", colour = brand_dark) +
  annotate("text", x = year_lo, y = med_fdi, label = paste0("median = ", f2(med_fdi), "% of GDP"),
           vjust = -0.7, hjust = 0, size = 3.5, colour = brand_dark) +
  scale_fill_manual(values = pal_fdi, name = NULL) +
  labs(title = "FDI net inflows", x = "Year", y = "% of GDP") + theme_brand()
(p_a / p_b) + plot_layout(guides = "collect") & theme(legend.position = "bottom")

r_h_year   <- cor(df_clean$HighFDI, df_clean$Year)
r_ren_year <- cor(df_clean$REN_ERG_CONS, df_clean$Year)
r_z_year   <- cor(df_clean$centr_logGDP, df_clean$Year)
Figure 2: Sudan’s renewable share (top) and FDI inflows (bottom). Colour shows the FDI regime; the dashed line is the median that defines it.
NoteWhat the numbers say
  • High-FDI years are scattered through time, not one early or late block (correlation between the dummy and the calendar year is only -0.07). The regimes are interleaved, so this is not simply “before vs after”.
  • Time, however, matters a lot: the renewable share has a correlation of -0.94 with the calendar year, and log GDP has 0.75. Both drift through time, which will matter when we interpret the GDP slope.
WarningCareful: the cut-off is a choice

Splitting at the median is convenient, but the 40th or the 60th percentile could also be used. Section 6.3 re-runs the key result for 17 different cut-offs to see whether the story depends on this choice.

3 First look: raw averages, no controls

Show R code
means_d1 <- df_clean |> group_by(FDI_Group) |> summarise(m = mean(REN_ERG_CONS), n = n(), .groups = "drop")
ggplot(df_clean, aes(FDI_Group, REN_ERG_CONS, colour = FDI_Group, fill = FDI_Group)) +
  geom_boxplot(width = 0.4, alpha = 0.15, outlier.shape = NA, linewidth = 0.8) +
  geom_jitter(width = 0.1, size = 2.6, alpha = 0.8) +
  geom_point(data = means_d1, aes(y = m), shape = 18, size = 5.5, colour = "#292929") +
  geom_text(data = means_d1, aes(y = m, label = paste0("mean ", f1(m), "%  (n = ", n, ")")),
            nudge_x = 0.36, fontface = "bold", size = 3.6, colour = "#292929") +
  scale_colour_manual(values = pal_fdi) + scale_fill_manual(values = pal_fdi) +
  labs(x = NULL, y = "Renewable share (% of final energy)") +
  theme_brand() + theme(legend.position = "none")
Figure 3: Renewable share by FDI regime. Boxes show median and quartiles, dots are years, diamonds are group means.
NoteWhat the numbers say

The two group averages differ by 0.64 pp (High-FDI years higher; p = 0.854, no clear evidence). Across all years the renewable share ranges over roughly 24.7 pp, so a 0.64 pp gap is a rounding error by comparison. (This gap is mathematically identical to the coefficient of a regression of the renewable share on the dummy alone.)

TipIn Simple Terms

At first glance the FDI regime seems irrelevant. But averages ignore that the two groups differ in other ways, above all in GDP. The six models below compare years at equal GDP, which is a fairer comparison.

4 The six models, one question at a time

4.1 Step 0: put GDP on a human scale (centring)

Show R code
rungs <- c(min(df_clean$GDP_bn), mean_gdp_bn, max(df_clean$GDP_bn))
data.frame(
  `GDP level` = c("Smallest in sample", "Typical (centre)", "Largest in sample"),
  `GDP (billion USD)` = rungs,
  `log GDP` = log(rungs),
  `Centred value used in the models` = log(rungs) - mean_lgdp,
  check.names = FALSE) |>
  brand_table("Centred log GDP: zero means 'Sudan at its typical GDP'", 2)
Centred log GDP: zero means 'Sudan at its typical GDP'
GDP level GDP (billion USD) log GDP Centred value used in the models
Smallest in sample 26.24 3.27 -0.56
Typical (centre) 45.97 3.83 0.00
Largest in sample 59.22 4.08 0.25
Show R code
gap_unc  <- unname(coef(m_inter_raw)["HighFDI"]); int_unc <- unname(coef(m_inter_raw)["(Intercept)"])
TipIn Simple Terms

Models use the centred variable \(z_t=\ln GDP_t-\overline{\ln GDP}\). Zero now means “Sudan at its typical GDP (about USD 46.0 bn)”. Because \(+10\%\) GDP equals \(+0.095\) on this scale, every GDP slope below is reported as “pp per +10% GDP”, which is a change you can picture.

WarningCareful: Centring the dummy is necessary

If GDP is not centred, the intercept and the dummy describe Sudan at log GDP = 0, i.e. a GDP of USD 1 bn, a size Sudan never had (the smallest observed is USD 26.2 bn). Estimated that way, the intercept would be 192.7% of renewable energy (impossible: above 100%) and the High-FDI “level shift” would be 47.7 pp. Centring changes none of the fitted lines (the fit is identical) but makes every coefficient describe a real Sudan. The joint F-tests are unaffected as well.

4.2 Model 1: one common line (the benchmark)

Question: if the FDI regime is ignored, how does the renewable share move with GDP?

\[REN_t=\beta_0+\beta_1\,z_t+u_t\]

Show R code
show_coef(m_base, "Model 1: one line for all years", 3)
Model 1: one line for all years
Term Estimate Std. error t statistic p-value Sig. 95% CI Plain reading
Intercept 69.285 0.894 77.519 < 0.001 *** [67.44, 71.13] Predicted share ≈ 69.3% for reference years at average GDP
GDP, centred log -33.317 4.064 -8.197 < 0.001 *** [-41.69, -24.95] −3.18 pp of renewable share for every +10% GDP
Show R code
s1 <- summary(m_base)
n1 <- list(int = unname(coef(m_base)[1]), slope10 = unname(coef(m_base)[2]) * k10,
           p = s1$coefficients[2, 4], adj = s1$adj.r.squared, sigma = s1$sigma)
NoteWhat the numbers say
  • Intercept ≈ 69.3%: at Sudan’s typical GDP, the model predicts a renewable share of about 69.3%.
  • Slope: every +10% GDP goes with −3.18 pp of renewable share (p < 0.001).
  • Fit: adjusted \(R^2\) = 0.72, so GDP alone accounts for about 71.8% of the year-to-year variation. A typical year is missed by about 4.6 pp.
WarningCareful: two things drifting through time

Both the renewable share and GDP trend through the calendar (correlations with year: -0.94 and 0.75). A strong slope can therefore reflect “two series moving through time” and not “GDP growth lowers renewables”. Remember this for every model that follows.

4.3 Model 2: parallel lines, a level shift

Question: at the same GDP, do High-FDI years sit higher or lower than Low-FDI years?

\[REN_t=\beta_0+\beta_1\,z_t+\beta_2\,D_{1t}+u_t \qquad H_0:\ \beta_2=0\]

Show R code
show_coef(m_int, "Model 2: parallel lines (intercept shift for High-FDI years)", 3)
Model 2: parallel lines (intercept shift for High-FDI years)
Term Estimate Std. error t statistic p-value Sig. 95% CI Plain reading
Intercept 67.542 1.174 57.552 < 0.001 *** [65.12, 69.96] Predicted share ≈ 67.5% for reference years at average GDP
GDP, centred log -34.914 3.881 -8.996 < 0.001 *** [-42.92, -26.90] −3.33 pp of renewable share for every +10% GDP
High-FDI year (D1) 3.620 1.708 2.119 0.045 * [0.09, 7.15] +3.62 pp vs reference years (at average GDP)
Show R code
show_ftest(m_base, m_int, "Does adding the High-FDI dummy help? Partial F-test (Model 1 vs Model 2)")
Does adding the High-FDI dummy help? Partial F-test (Model 1 vs Model 2)
Model Res. df RSS Extra terms RSS saved F p-value Verdict
Restricted (simpler) 25 539.227 – – – – –
Unrestricted (richer) 24 454.210 1 85.017 4.492 0.045 The extra terms earn their place
Show R code
ci2 <- confint(m_int)["HighFDI", ]
NoteWhat the numbers say
  • The dummy (β₂): at the same GDP, High-FDI years have a renewable share 3.62 pp higher than Low-FDI years. The 95% interval runs from +0.09 to +7.15 pp: it excludes zero, so the data show moderate evidence (p = 0.045) of a gap.
  • F-test: adding the dummy reduces the unexplained variation by 15.8% (F = 4.49, p = 0.045). With one extra term, this F-test is equivalent to the dummy’s own t-test.
  • The slope is unchanged in spirit: every +10% GDP still goes with about −3.33 pp in both regimes: parallel lines have a common tilt by construction.
Show R code
data.frame(
  Piece = c("Gap at the same GDP (the Model 2 dummy)",
            "GDP head-start of High-FDI years × GDP slope",
            "= Raw gap in simple averages (the boxplot above)"),
  `pp of renewable share` = c(gap_ctrl, pull, gap_raw),
  `How to read it` = c(
    "High-FDI vs Low-FDI years that have identical GDP",
    sprintf("High-FDI years had %.1f%% %s GDP on average, and GDP goes with %s pp per +10%%",
            100 * abs(exp(dz) - 1), ifelse(dz >= 0, "more", "less"), sgn(coef(m_int)["centr_logGDP"] * k10)),
    "What a naive comparison of averages shows"),
  check.names = FALSE) |>
  brand_table("Why the raw gap and the same-GDP gap differ (an exact accounting identity)", 2)
Why the raw gap and the same-GDP gap differ (an exact accounting identity)
Piece pp of renewable share How to read it
Gap at the same GDP (the Model 2 dummy) 3.62 High-FDI vs Low-FDI years that have identical GDP
GDP head-start of High-FDI years × GDP slope -2.98 High-FDI years had 8.9% more GDP on average, and GDP goes with −3.33 pp per +10%
= Raw gap in simple averages (the boxplot above) 0.64 What a naive comparison of averages shows
TipIn Simple Terms

The raw gap is the sum of two ingredients: the true same-GDP gap and a GDP “head-start” effect. Raw averages hide part of the gap because High-FDI years were also richer years (about 8.9% higher GDP on average), and that GDP difference alone moves the renewable share by −2.98 pp, which cancels part of the FDI gap. Comparing years of equal GDP removes this: the gap moves from 0.64 to 3.62 pp. The model removes the head-start by comparing like with like.

Show R code
grid_z <- seq(min(df_clean$centr_logGDP), max(df_clean$centr_logGDP), length.out = 100)
pred_for <- function(model, extra = NULL) {
  g <- expand.grid(centr_logGDP = grid_z, HighFDI = c(0, 1))
  if (!is.null(extra)) g <- cbind(g, extra)
  p <- cbind(g, predict(model, newdata = g, interval = "confidence"))
  p$FDI_Group <- factor(p$HighFDI, levels = 0:1, labels = levels(df_clean$FDI_Group))
  p$GDP_bn <- exp(p$centr_logGDP + mean_lgdp)
  p
}
regime_plot <- function(pred, title, subtitle, show_y = TRUE) {
  ggplot() +
    geom_ribbon(data = pred, aes(GDP_bn, ymin = lwr, ymax = upr, fill = FDI_Group), alpha = 0.15) +
    geom_line(data = pred, aes(GDP_bn, fit, colour = FDI_Group), linewidth = 1.2) +
    geom_point(data = df_clean, aes(GDP_bn, REN_ERG_CONS, colour = FDI_Group), size = 2.4, alpha = 0.85) +
    geom_text(data = df_clean, aes(GDP_bn, REN_ERG_CONS, label = sprintf("'%02d", Year %% 100), colour = FDI_Group),
              size = 2.7, vjust = -1, check_overlap = TRUE, show.legend = FALSE) +
    scale_x_log10(breaks = c(25, 30, 40, 50, 60)) +
    scale_colour_manual(values = pal_fdi, name = NULL) + scale_fill_manual(values = pal_fdi, name = NULL) +
    labs(title = title, subtitle = subtitle, x = "GDP (billion USD, log scale)",
         y = if (show_y) "Renewable share (% of final energy)" else NULL) +
    theme_brand()
}
pred_int <- pred_for(m_int)
regime_plot(pred_int, "Model 2: parallel lines",
            paste0("Vertical gap between the lines = ", sgn(gap_ctrl), " pp at every GDP level"))
Figure 4: Model 2: two parallel lines with 95% confidence bands for the mean. Labels are years.
NoteWhat the picture says

The two lines fall from left to right (more GDP, lower renewable share). The red line sits 3.62 pp above the blue line everywhere. The shaded bands overlap only partly, which is the picture version of “moderate evidence”.

4.4 Model 3: same start, different tilt

Question: do the lines meet at one point but tilt differently?

\[REN_t=\beta_0+\beta_1\,z_t+\beta_2\,(z_t\cdot D_{1t})+u_t\]

Show R code
show_coef(m_slope, "Model 3: common intercept, slope shift only", 3)
Model 3: common intercept, slope shift only
Term Estimate Std. error t statistic p-value Sig. 95% CI Plain reading
Intercept 69.455 0.928 74.822 < 0.001 *** [67.54, 71.37] Predicted share ≈ 69.5% for reference years at average GDP
GDP, centred log -31.666 4.633 -6.834 < 0.001 *** [-41.23, -22.10] −3.02 pp of renewable share for every +10% GDP
GDP × High-FDI (D1) -7.947 10.406 -0.764 0.452 [-29.43, 13.53] High-FDI slope differs by −0.76 pp per +10% GDP
Show R code
show_ftest(m_base, m_slope, "Partial F-test: Model 1 vs Model 3")
Partial F-test: Model 1 vs Model 3
Model Res. df RSS Extra terms RSS saved F p-value Verdict
Restricted (simpler) 25 539.227 – – – – –
Unrestricted (richer) 24 526.433 1 12.793 0.583 0.452 No clear gain from the extra terms
Show R code
aic_cen <- AIC(m_slope); aic_raw <- AIC(m_slope_raw)
NoteWhat the numbers say

The tilt difference is −0.76 pp per +10% GDP (p = 0.452), so the tilt is not statistically significant at 5%. With a single extra term the F-test and this t-test are the same test.

WarningCareful: Model 3 depends on where you place the origin

Forcing both lines through the same point means “the regimes are identical at zero”. With centred GDP that point is Sudan’s typical GDP; with uncentred GDP it is USD 1 bn. The same type of model then fits differently: AIC = 164.82 (centred) vs 161.09 (uncentred), a difference of 3.73 units caused only by an arbitrary choice of origin. A result that changes when you shift the axis is not a finding about Sudan. That it is recommended to keep the main effect (the dummy) whenever an interaction is in the model, which is exactly Model 4.

4.5 Model 4: level and tilt can both differ

Question: do the two regimes follow different lines altogether?

\[REN_t=\beta_0+\beta_1\,z_t+\beta_2\,D_{1t}+\beta_3\,(z_t\cdot D_{1t})+u_t\]

Show R code
show_coef(m_inter, "Model 4: full interaction", 3)
Model 4: full interaction
Term Estimate Std. error t statistic p-value Sig. 95% CI Plain reading
Intercept 67.634 1.167 57.960 < 0.001 *** [65.22, 70.05] Predicted share ≈ 67.6% for reference years at average GDP
GDP, centred log -32.680 4.293 -7.613 < 0.001 *** [-41.56, -23.80] −3.11 pp of renewable share for every +10% GDP
High-FDI year (D1) 3.936 1.716 2.294 0.031 * [0.39, 7.48] +3.94 pp vs reference years (at average GDP)
GDP × High-FDI (D1) -11.427 9.709 -1.177 0.251 [-31.51, 8.66] High-FDI slope differs by −1.09 pp per +10% GDP
Show R code
b <- coef(m_inter); V <- vcov(m_inter); tq <- qt(0.975, df.residual(m_inter))
lincomb <- function(w) {
  w <- replace(setNames(numeric(length(b)), names(b)), names(w), w)
  est <- sum(w * b); se <- sqrt(drop(t(w) %*% V %*% w))
  c(est = est, se = se, lo = est - tq * se, hi = est + tq * se)
}
rl <- rbind(lincomb(c("(Intercept)" = 1)),
            lincomb(c("(Intercept)" = 1, "HighFDI" = 1)),
            lincomb(c("centr_logGDP" = k10)),
            lincomb(c("centr_logGDP" = k10, "centr_logGDP:HighFDI" = k10)),
            lincomb(c("HighFDI" = 1)),
            lincomb(c("centr_logGDP:HighFDI" = k10)))
reg_tab <- data.frame(
  Quantity = c("Level at typical GDP, Low-FDI years", "Level at typical GDP, High-FDI years",
               "Slope (pp per +10% GDP), Low-FDI years", "Slope (pp per +10% GDP), High-FDI years",
               "Level gap at typical GDP (High − Low)", "Slope difference (High − Low), pp per +10% GDP"),
  Estimate = rl[, "est"], `Std. error` = rl[, "se"], `95% CI low` = rl[, "lo"], `95% CI high` = rl[, "hi"],
  check.names = FALSE)
brand_table(reg_tab, "What Model 4 implies for each regime, with exact standard errors", 2)
What Model 4 implies for each regime, with exact standard errors
Quantity Estimate Std. error 95% CI low 95% CI high
Level at typical GDP, Low-FDI years 67.63 1.17 65.22 70.05
Level at typical GDP, High-FDI years 71.57 1.26 68.97 74.17
Slope (pp per +10% GDP), Low-FDI years -3.11 0.41 -3.96 -2.27
Slope (pp per +10% GDP), High-FDI years -4.20 0.83 -5.92 -2.49
Level gap at typical GDP (High − Low) 3.94 1.72 0.39 7.48
Slope difference (High − Low), pp per +10% GDP -1.09 0.93 -3.00 0.83
Show R code
# self-check: Model 4 is exactly two separate regressions
sep_high <- coef(lm(REN_ERG_CONS ~ centr_logGDP, data = subset(df_clean, HighFDI == 1)))
stopifnot(isTRUE(all.equal(unname(sep_high), unname(c(sum(b[c("(Intercept)", "HighFDI")]),
                                                      sum(b[c("centr_logGDP", "centr_logGDP:HighFDI")]))))))
show_ftest(m_int, m_inter, "Is the tilt difference needed? Incremental F-test (Model 2 vs Model 4)")
Is the tilt difference needed? Incremental F-test (Model 2 vs Model 4)
Model Res. df RSS Extra terms RSS saved F p-value Verdict
Restricted (simpler) 24 454.210 – – – – –
Unrestricted (richer) 23 428.409 1 25.801 1.385 0.251 No clear gain from the extra terms
Show R code
show_ftest(m_base, m_inter, "Are the two regime lines identical? Joint (Chow-style) F-test (Model 1 vs Model 4)")
Are the two regime lines identical? Joint (Chow-style) F-test (Model 1 vs Model 4)
Model Res. df RSS Extra terms RSS saved F p-value Verdict
Restricted (simpler) 25 539.227 – – – – –
Unrestricted (richer) 23 428.409 2 110.818 2.975 0.071 Borderline
Show R code
b3_10 <- unname(coef(m_inter)["centr_logGDP:HighFDI"]) * k10
NoteWhat the numbers say
  • Low-FDI years: at typical GDP the renewable share is about 67.6%, and every +10% GDP goes with −3.11 pp.
  • High-FDI years: the level is about 71.6%, and the slope is −4.20 pp per +10% GDP.
  • Tilt difference: −1.09 pp per +10% GDP, not statistically significant at 5% (p = 0.251). The two regimes respond to GDP growth in about the same way.
  • Are the lines identical overall? The joint test gives p = 0.071: only weak evidence that the regimes follow different lines.
TipIn Simple Terms

Model 4 is the “separate rules for each group” model. Its joint test (p = 0.071) is less convincing than the simple level shift of Model 2 (p = 0.045). The reason: the joint test spends two extra parameters, and when the second one (the tilt) adds little, it dilutes the evidence for the first. Extra flexibility has to pay for itself.

Show R code
pred_inter <- pred_for(m_inter)
(regime_plot(pred_int, "A. Parallel lines (Model 2)", "One tilt, shifted level") |
   regime_plot(pred_inter, "B. Separate lines (Model 4)",
               paste0("Tilts differ by ", sgn(b3_10), " pp per +10% GDP"), show_y = FALSE)) +
  plot_layout(guides = "collect") & theme(legend.position = "bottom")
Figure 5: Parallel lines (Model 2, left) versus separate lines (Model 4, right), with 95% confidence bands.
Show R code
z_lo <- max(min(df_clean$centr_logGDP[df_clean$HighFDI == 1]), min(df_clean$centr_logGDP[df_clean$HighFDI == 0]))
z_hi <- min(max(df_clean$centr_logGDP[df_clean$HighFDI == 1]), max(df_clean$centr_logGDP[df_clean$HighFDI == 0]))
zz <- seq(min(df_clean$centr_logGDP), max(df_clean$centr_logGDP), length.out = 200)
gap_est <- b["HighFDI"] + b["centr_logGDP:HighFDI"] * zz
gap_se  <- sqrt(V["HighFDI", "HighFDI"] + zz^2 * V["centr_logGDP:HighFDI", "centr_logGDP:HighFDI"] +
                  2 * zz * V["HighFDI", "centr_logGDP:HighFDI"])
gap_est <- unname(gap_est)
gc <- data.frame(GDP_bn = exp(zz + mean_lgdp), z = zz, gap = gap_est, lo = gap_est - tq * gap_se, hi = gap_est + tq * gap_se)
gc$sig <- gc$lo > 0 | gc$hi < 0
gc$common <- gc$z >= z_lo & gc$z <= z_hi

ggplot(gc, aes(GDP_bn, gap)) +
  annotate("rect", xmin = exp(z_lo + mean_lgdp), xmax = exp(z_hi + mean_lgdp), ymin = -Inf, ymax = Inf,
           fill = "grey85", alpha = 0.6) +
  geom_hline(yintercept = 0, linetype = "dashed", colour = "grey40") +
  geom_ribbon(aes(ymin = lo, ymax = hi), fill = brand, alpha = 0.15) +
  geom_line(colour = brand, linewidth = 1.2) +
  geom_rug(data = df_clean, aes(x = GDP_bn, colour = FDI_Group), inherit.aes = FALSE, sides = "b", linewidth = 0.8) +
  scale_colour_manual(values = pal_fdi, name = "Observed years") +
  scale_x_log10(breaks = c(25, 30, 40, 50, 60)) +
  labs(title = "Where do the two regimes differ?", x = "GDP (billion USD, log scale)",
       y = "High-FDI minus Low-FDI renewable share (pp)") +
  theme_brand()

Model 4: the High-FDI minus Low-FDI gap at each GDP level, with 95% band. The grey zone is where both regimes have observed years.
Show R code
sig_c <- gc[gc$sig & gc$common, ]
sig_txt <- if (nrow(sig_c)) sprintf("from about USD %.0f bn to USD %.0f bn", min(sig_c$GDP_bn), max(sig_c$GDP_bn)) else "nowhere"
gap_at <- function(zv) unname(b["HighFDI"] + b["centr_logGDP:HighFDI"] * zv)
NoteWhat the picture says

At the low end of the shared GDP range (about USD 35.4 bn) the estimated gap is +6.9 pp; at typical GDP it is +3.9 pp; at the high end (about USD 58.6 bn) it is +1.2 pp. Within the zone where both regimes actually have years, the band excludes zero from about USD 35 bn to USD 48 bn. Outside the grey zone the lines are extrapolations: one regime has no years there, so those gaps should not be trusted.

4.6 Model 5: two dummies, FDI and trade

Question: once the FDI regime is accounted for, does trade openness add anything?

\[REN_t=\beta_0+\beta_1\,z_t+\beta_2\,D_{1t}+\beta_3\,D_{2t}+u_t \qquad H_0:\ \beta_3=0\]

Show R code
cell <- df_clean |>
  group_by(FDI_Group, Trade_Group) |>
  summarise(n = n(), mean_ren = mean(REN_ERG_CONS), .groups = "drop") |>
  mutate(label = paste0("n = ", n, "\nmean ", f1(mean_ren), "%"))
n_cells <- nrow(cell); r_dd <- cor(df_clean$HighFDI, df_clean$HighTrade)
vif5 <- car::vif(m_dual)
rank5 <- qr(model.matrix(m_dual))$rank

show_coef(m_dual, "Model 5: FDI and trade dummies together", 3)
Model 5: FDI and trade dummies together
Term Estimate Std. error t statistic p-value Sig. 95% CI Plain reading
Intercept 65.356 1.137 57.473 < 0.001 *** [63.00, 67.71] Predicted share ≈ 65.4% for reference years at average GDP
GDP, centred log -39.870 3.462 -11.515 < 0.001 *** [-47.03, -32.71] −3.80 pp of renewable share for every +10% GDP
High-FDI year (D1) 2.611 1.425 1.831 0.080 . [-0.34, 5.56] +2.61 pp vs reference years (at average GDP)
High-trade year (D2) 5.550 1.547 3.587 0.002 ** [2.35, 8.75] +5.55 pp vs reference years (at average GDP)
Show R code
show_ftest(m_int, m_dual, "Does trade openness add information beyond FDI? Partial F-test (Model 2 vs Model 5)")
Does trade openness add information beyond FDI? Partial F-test (Model 2 vs Model 5)
Model Res. df RSS Extra terms RSS saved F p-value Verdict
Restricted (simpler) 24 454.210 – – – – –
Unrestricted (richer) 23 291.286 1 162.924 12.864 0.002 The extra terms earn their place
Show R code
ggplot(cell, aes(FDI_Group, Trade_Group, fill = mean_ren)) +
  geom_tile(colour = "white", linewidth = 2) +
  geom_text(aes(label = label), fontface = "bold", size = 4.2, colour = "#292929") +
  scale_fill_gradient(low = "#EAF1F8", high = "#F2B8BC", name = "Mean renewable\nshare (%)") +
  labs(x = "FDI regime (D1)", y = "Trade regime (D2)") +
  theme_brand() + theme(panel.grid = element_blank(), legend.position = "right")
Figure 6: How Sudan’s years fall into the four FDI × trade combinations (count and average renewable share).
NoteWhat the numbers say
  • High-trade years (β₃): at the same GDP and FDI regime, they have a renewable share 5.55 pp higher (p = 0.002, strong evidence). Adding this single switch removes 35.9% of the variation that Model 2 left unexplained (F = 12.86).
  • The FDI gap shrinks: from +3.62 pp in Model 2 to +2.61 pp here (p = 0.080, only weak evidence). Part of what looked like an “FDI regime effect” was shared with the trade regime.
  • No dummy-variable trap: all 4 of the 4 FDI × trade cells contain years, the design matrix has full rank (4 of 4 columns), and the two dummies are only mildly related (correlation 0.26; largest VIF 1.27), so they do not compete for the same information.
WarningCareful: a dummy can be driven by a few years

In this sample, trade openness falls sharply in the final years (Trade_GDP = 10.0% in 2020 and 4.1% in 2021, against a median of 24.7%). Section 6.4 checks whether a handful of years, not a lasting pattern, produce the trade result.

4.7 Model 6: three industry tiers

Question: does industry’s share of GDP (Low / Medium / High) shift the line?

\[REN_t=\beta_0+\beta_1\,z_t+\gamma_1\,D_{Medium,t}+\gamma_2\,D_{High,t}+u_t\]

Show R code
show_coef(m_poly, "Model 6: industry tiers (reference = Low)", 3)
Model 6: industry tiers (reference = Low)
Term Estimate Std. error t statistic p-value Sig. 95% CI Plain reading
Intercept 66.450 1.662 39.985 < 0.001 *** [63.01, 69.89] Predicted share ≈ 66.4% for reference years at average GDP
GDP, centred log -37.975 4.656 -8.156 < 0.001 *** [-47.61, -28.34] −3.62 pp of renewable share for every +10% GDP
Industry tier: Medium 4.233 2.279 1.858 0.076 . [-0.48, 8.95] +4.23 pp vs reference years (at average GDP)
Industry tier: High 4.273 2.498 1.711 0.101 [-0.89, 9.44] +4.27 pp vs reference years (at average GDP)
Show R code
show_ftest(m_base, m_poly, "Do the industry tiers matter jointly? F-test (Model 1 vs Model 6)")
Do the industry tiers matter jointly? F-test (Model 1 vs Model 6)
Model Res. df RSS Extra terms RSS saved F p-value Verdict
Restricted (simpler) 25 539.227 – – – – –
Unrestricted (richer) 23 459.032 2 80.195 2.009 0.157 No clear gain from the extra terms
Show R code
b6 <- coef(m_poly); p6 <- summary(m_poly)$coefficients[, 4]
NoteWhat the numbers say

Medium-industry years sit 4.23 pp higher than Low-industry years of the same GDP (p = 0.076), and High-industry years 4.27 pp higher (p = 0.101). Each coefficient is a comparison with the Low group only; to judge the factor as a whole, use the joint F-test: p = 0.157, so there is no clear evidence that industrial structure matters beyond GDP.

Show R code
df_trap <- df_clean |> mutate(D_Low = as.integer(IndTier == "Low"), D_Medium = as.integer(IndTier == "Medium"),
                              D_High = as.integer(IndTier == "High"))
m_trap <- lm(REN_ERG_CONS ~ centr_logGDP + D_Low + D_Medium + D_High, data = df_trap)
Xtrap <- model.matrix(m_trap)
data.frame(Term = names(coef(m_trap)), Estimate = unname(coef(m_trap)),
           Status = ifelse(is.na(coef(m_trap)), "ALIASED: R cannot estimate it", "estimated")) |>
  brand_table("The dummy-variable trap: three tier dummies plus an intercept", 3,
              bold_rows = which(is.na(coef(m_trap))))
The dummy-variable trap: three tier dummies plus an intercept
Term Estimate Status
(Intercept) 70.723 estimated
centr_logGDP -37.975 estimated
D_Low -4.273 estimated
D_Medium -0.039 estimated
D_High – ALIASED: R cannot estimate it
TipIn Simple Terms: why R drops one dummy

With an intercept in the model, the three tier switches always add up to 1 (every year is in exactly one tier), which is the intercept column. R is then asked to answer one question twice. The design matrix has 5 columns but only 4 independent ones, so R marks one coefficient NA. The rule: with m categories and an intercept, use m − 1 dummies; the omitted one becomes the reference group.

5 Scoreboard: which model fits best?

Show R code
ev_word <- function(d) ifelse(d < 0.001, "– (best)", ifelse(d < 2, "barely distinguishable",
                       ifelse(d < 6, "positive evidence against", ifelse(d < 10, "strong evidence against",
                                                                          "very strong evidence against"))))
sb <- data.frame(Model = glance_all$Model, `Parameters` = glance_all$k, `R²` = glance_all$R2,
                 `Adj. R²` = glance_all$adjR2, `Typical miss (pp)` = glance_all$sigma,
                 AIC = glance_all$AIC, BIC = glance_all$BIC, `ΔBIC vs best` = glance_all$dBIC,
                 `Evidence against this model (BIC)` = ev_word(glance_all$dBIC), check.names = FALSE)
brand_table(sb, "Fit statistics on the common sample (bold row = lowest BIC)", 3, bold_rows = best_i)
Fit statistics on the common sample (bold row = lowest BIC)
Model Parameters R² Adj. R² Typical miss (pp) AIC BIC ΔBIC vs best Evidence against this model (BIC)
M1 One common line 2 0.729 0.718 4.644 163.469 167.356 10.036 very strong evidence against
M2 Parallel lines (level shifts) 3 0.772 0.753 4.350 160.836 166.020 8.699 strong evidence against
M3 Same start, different tilt 3 0.735 0.713 4.683 164.820 170.004 12.683 very strong evidence against
M4 Level and tilt (interaction) 4 0.785 0.756 4.316 161.257 167.736 10.416 very strong evidence against
M5 Two dummies (FDI + trade) 4 0.854 0.834 3.559 150.841 157.321 0.000 – (best)
M6 Three industry tiers 4 0.769 0.739 4.467 163.121 169.600 12.280 very strong evidence against
Show R code
ggplot(glance_all, aes(dBIC, reorder(Model, -dBIC), colour = dBIC < 0.001)) +
  geom_vline(xintercept = c(2, 6, 10), linetype = "dashed", colour = "grey60") +
  geom_segment(aes(x = 0, xend = dBIC, yend = reorder(Model, -dBIC)), linewidth = 1.6) +
  geom_point(size = 4.5) +
  scale_colour_manual(values = c("TRUE" = brand, "FALSE" = brand_blue), guide = "none") +
  labs(x = "ΔBIC (higher = worse than the best model)", y = NULL) +
  theme_brand()
sec_i <- order(glance_all$BIC)[2]
Figure 7: Distance of every model from the best BIC. Dashed lines mark the usual ‘positive’, ‘strong’ and ‘very strong’ evidence thresholds (2, 6, 10).
NoteWhat the numbers say

M5 has the lowest BIC and also the lowest AIC. It misses a typical year by about 3.6 pp, and explains 83.4% of the variation (adjusted). The runner-up, M2, is 8.7 BIC units behind: strong evidence against. The weakest model on this scale is M3 (12.7 units behind). Remember that \(R^2\) can only go up when terms are added, so only adjusted \(R^2\), AIC and BIC are fair for choosing.

6 Stress tests: can we trust these p-values?

6.1 Errors that remember last year

Show R code
dwt <- data.frame(Model = dw_tab$Model, `Durbin–Watson` = dw_tab$DW, `p (Durbin–Watson)` = fmt_p(dw_tab$p_DW),
                  `p (Breusch–Godfrey, 2 lags)` = fmt_p(dw_tab$p_BG),
                  Reading = ifelse(dw_tab$p_DW < 0.05 & dw_tab$p_BG < 0.05, "Errors clearly persist",
                            ifelse(dw_tab$p_DW < 0.05 | dw_tab$p_BG < 0.05, "Some persistence", "No clear persistence")),
                  check.names = FALSE)
brand_table(dwt, "Residual autocorrelation tests (a Durbin–Watson value near 2 means no first-order autocorrelation)", 3, bold_rows = best_i)
Residual autocorrelation tests (a Durbin–Watson value near 2 means no first-order autocorrelation)
Model Durbin–Watson p (Durbin–Watson) p (Breusch–Godfrey, 2 lags) Reading
M1 One common line 0.197 < 0.001 < 0.001 Errors clearly persist
M2 Parallel lines (level shifts) 0.719 < 0.001 < 0.001 Errors clearly persist
M3 Same start, different tilt 0.230 < 0.001 < 0.001 Errors clearly persist
M4 Level and tilt (interaction) 0.799 < 0.001 < 0.001 Errors clearly persist
M5 Two dummies (FDI + trade) 1.274 0.010 0.130 Some persistence
M6 Three industry tiers 0.390 < 0.001 < 0.001 Errors clearly persist
Show R code
n_dw_bad <- sum(dw_tab$p_DW < 0.05)
NoteWhat the numbers say

The Durbin–Watson value is far below 2 for most models (Model 1: 0.20; best model M5: 1.27), and 6 of 6 models fail the test at 5%. In plain terms: a year’s unexplained gap tends to be followed by a gap of the same sign the next year. Ordinary standard errors assume otherwise, so they are too small, and p-values are too optimistic. The best model improves the problem (M5 has the highest DW) but does not remove it.

6.2 Do the conclusions survive honest standard errors? (HAC)

Show R code
hac_show <- data.frame(
  Question = hac_tab$Question, `Estimate (pp)` = hac_tab$Estimate,
  `p (classical)` = fmt_p(hac_tab$p_classic), `p (HAC)` = fmt_p(hac_tab$p_hac),
  `Same verdict at 5%?` = ifelse((hac_tab$p_classic < 0.05) == (hac_tab$p_hac < 0.05), "Yes", "No: flips"),
  Strength = hac_tab$Strength, check.names = FALSE)
brand_table(hac_show, "Classical vs Newey–West (HAC) p-values for every headline question", 3)
Classical vs Newey–West (HAC) p-values for every headline question
Question Estimate (pp) p (classical) p (HAC) Same verdict at 5%? Strength
M2: do High-FDI years sit at a different level (same GDP)? 3.620 0.045 0.088 No: flips Fragile
M4: does the GDP slope differ between regimes? -1.089 0.251 0.049 No: flips Fragile
M4: are the two regime lines identical (level and tilt)? – 0.071 0.065 Yes Weak
M5: High-FDI gap, once trade regime is controlled 2.611 0.080 0.102 Yes Weak
M5: High-trade gap, once FDI regime is controlled 5.550 0.002 < 0.001 Yes Robust
M6: do the industry tiers matter (jointly)? – 0.157 0.115 Yes No clear evidence
Show R code
n_flip <- sum((hac_tab$p_classic < 0.05) != (hac_tab$p_hac < 0.05))
NoteWhat the numbers say

Re-testing with HAC standard errors flips the 5% verdict for 2 of 6 questions. For the headline FDI question (M2), the p-value moves from 0.045 to 0.088, so it is rated “Fragile”. The High-trade gap in Model 5 stays far below 5% under both methods (0.002 and < 0.001): rated “Robust”. HAC corrections can move p-values either way, so read this table as “which findings are stable?”, not as a new set of tests to pick from.

WarningCareful

HAC standard errors rely on large samples, and 27 annual observations is small. Treat this as a sensitivity check. And note that HAC fixes only the uncertainty, not the fact that the regressors may be tracking time (see the timeline in Section 2.3).

6.3 Does the answer depend on where the line is drawn?

Show R code
pA <- ggplot(sens, aes(q, gap)) +
  geom_hline(yintercept = 0, colour = "grey40", linetype = "dashed") +
  geom_vline(xintercept = 0.5, colour = brand_dark, linetype = "dotted") +
  geom_ribbon(aes(ymin = lo, ymax = hi), fill = brand, alpha = 0.15) +
  geom_line(colour = brand, linewidth = 1.1) + geom_point(colour = brand, size = 2) +
  scale_x_continuous(labels = scales::percent_format(accuracy = 1)) +
  labs(title = "Estimated High-FDI gap at the same GDP", x = NULL, y = "pp of renewable share") + theme_brand()
pB <- sens |> select(q, `Gap test (Model 2)` = p_gap, `Joint test (Model 4 vs 1)` = p_joint) |>
  pivot_longer(-q, names_to = "Test", values_to = "p") |>
  ggplot(aes(q, p, colour = Test)) +
  geom_hline(yintercept = 0.05, colour = "grey40", linetype = "dashed") +
  geom_vline(xintercept = 0.5, colour = brand_dark, linetype = "dotted") +
  geom_line(linewidth = 1.1) + geom_point(size = 2) +
  scale_colour_manual(values = c(brand, brand_blue), name = NULL) +
  scale_x_continuous(labels = scales::percent_format(accuracy = 1)) +
  labs(title = "p-values", x = "Cut-off: a year is 'High-FDI' when FDI is above this percentile", y = "p-value") + theme_brand()
pA / pB

med_row <- sens[abs(sens$q - 0.5) < 1e-9, ]
n_pos <- sum(sens$gap > 0); n_neg <- sum(sens$gap < 0)
n_joint_sig <- sum(sens$p_joint < 0.05)
rank_med <- sum(sens$p_gap < med_row$p_gap) + 1
Figure 8: Cut-off sensitivity: the FDI regime is redefined at 17 different percentiles. Top: the level gap and its 95% interval. Bottom: p-values (dashed = 0.05). The dotted vertical line is the median used in the main text.
NoteWhat the numbers say

Across 17 cut-offs from the 30th to the 70th percentile, the estimated gap is positive in 17 and negative in 0 cut-offs and ranges from 3.29 to 5.04 pp. It is statistically significant at 5% in 16 of 17 cut-offs, and the joint test in 11. The median used in the main text (p = 0.045) is among the less favourable cut-offs (rank 15 of 17 from most to least significant). So the direction and rough size of the gap are stable; its significance is not guaranteed: it depends on the chosen line and on how the errors are treated (previous section). A fair write-up reports a range, not a single p-value.

6.4 Could a few years be driving the result?

Show R code
cd <- cooks.distance(best_m)
top <- order(-cd)[1:3]
infl <- data.frame(Year = df_clean$Year[top], `Cook's distance` = unname(cd[top]),
                   `Rule of thumb (4/N)` = 4 / N_obs, `FDI regime` = as.character(df_clean$FDI_Group[top]),
                   `Trade regime` = as.character(df_clean$Trade_Group[top]),
                   `Renewable share (%)` = df_clean$REN_ERG_CONS[top], check.names = FALSE)
brand_table(infl, paste0("The three most influential years in ", best_short, " (Cook's distance)"), 3)
The three most influential years in M5 (Cook's distance)
Year Cook's distance Rule of thumb (4/N) FDI regime Trade regime Renewable share (%)
1995 0.434 0.148 Low-FDI year Low-trade year 81.5
2019 0.187 0.148 Low-FDI year High-trade year 59.4
2001 0.134 0.148 High-FDI year Low-trade year 79.4
Show R code
drop_idx <- which.max(cd)
m_leave <- update(best_m, data = df_clean[-drop_idx, ])
cmp <- data.frame(Term = term_label(names(coef(best_m))), `All years` = unname(coef(best_m)),
                  `Without most influential year` = unname(coef(m_leave)),
                  `p (all years)` = fmt_p(summary(best_m)$coefficients[, 4]),
                  `p (without)` = fmt_p(summary(m_leave)$coefficients[, 4]), check.names = FALSE)
brand_table(cmp, paste0(best_short, " with and without ", df_clean$Year[drop_idx]), 3)
M5 with and without 1995
Term All years Without most influential year p (all years) p (without)
Intercept 65.356 65.762 < 0.001 < 0.001
GDP, centred log -39.870 -43.636 < 0.001 < 0.001
High-FDI year (D1) 2.611 2.263 0.080 0.101
High-trade year (D2) 5.550 5.726 0.002 < 0.001
Show R code
# the same question for the last two years (the trade collapse)
last2 <- df_clean$Year %in% c(year_hi - 1, year_hi)
m_last2 <- update(m_dual, data = df_clean[!last2, ])
b_tr_all <- unname(coef(m_dual)["HighTrade"]); b_tr_drop <- unname(coef(m_last2)["HighTrade"])
p_tr_drop <- summary(m_last2)$coefficients["HighTrade", 4]
NoteWhat the numbers say

The most influential year in M5 is 1995 (Cook’s distance 0.43, above the usual 4/N = 0.15 warning level). Dropping it leaves every coefficient with the same sign. Separately, dropping the two years when trade collapsed (2020 and 2021) changes the High-trade gap from +5.55 to +5.33 pp (p = 0.005), so the trade result does not hinge on those two years.

6.5 Residuals of the best model

Show R code
aug <- broom::augment(best_m)
aug$Year <- df_clean$Year
d1 <- ggplot(aug, aes(.fitted, .resid)) +
  geom_hline(yintercept = 0, linetype = "dashed", colour = brand) +
  geom_point(colour = brand_blue, size = 2.4, alpha = 0.85) +
  geom_smooth(method = "loess", formula = y ~ x, se = FALSE, colour = "#292929", linewidth = 0.8) +
  labs(title = "Residuals vs fitted", x = "Fitted values (pp)", y = "Residual (pp)") + theme_brand()
d2 <- ggplot(aug, aes(sample = .std.resid)) +
  stat_qq(colour = brand_blue, size = 2.4) + stat_qq_line(colour = brand, linewidth = 0.9) +
  labs(title = "Normal Q–Q", x = "Theoretical quantiles", y = "Standardised residuals") + theme_brand()
d3 <- ggplot(aug, aes(Year, .resid)) +
  geom_hline(yintercept = 0, linetype = "dashed", colour = brand) +
  geom_line(colour = "grey70") + geom_point(colour = brand_blue, size = 2.4) +
  labs(title = "Residuals over time", x = "Year", y = "Residual (pp)") + theme_brand()
d1 | d2 | d3

runs_changes <- sum(diff(sign(aug$.resid)) != 0)
jb_p <- tryCatch(shapiro.test(aug$.resid)$p.value, error = function(e) NA_real_)
Figure 9: Residual checks for the best model: residuals vs fitted values (left), normal Q–Q (middle), residuals over time (right).
NoteWhat the pictures say
  • Left: a flat smoother around zero means no missed curvature. With only 27 points, treat small wiggles as noise and only a clear arch or bowl as a warning.
  • Middle: points close to the line mean roughly normal residuals (Shapiro–Wilk p = 0.129: normality is not rejected).
  • Right: residuals change sign only 10 times in 26 year-to-year steps. Long same-sign stretches are the picture version of the autocorrelation found above.

7 Final verdict

Show R code
claims <- data.frame(
  Claim = c("High-FDI years sit at a different level than Low-FDI years of the same GDP",
            "The GDP effect (slope) differs between FDI regimes",
            "High-trade years sit at a different level, once FDI regime is controlled",
            "Industrial structure (three tiers) shifts the line beyond GDP"),
  `Estimate` = c(paste0(sgn(hac_tab$Estimate[i_fdi]), " pp"),
                 paste0(sgn(hac_tab$Estimate[i_slope]), " pp per +10% GDP"),
                 paste0(sgn(hac_tab$Estimate[i_trade5]), " pp"), "–"),
  `p (classical)` = fmt_p(hac_tab$p_classic[c(i_fdi, i_slope, i_trade5, i_tier)]),
  `p (HAC)` = fmt_p(hac_tab$p_hac[c(i_fdi, i_slope, i_trade5, i_tier)]),
  Strength = hac_tab$Strength[c(i_fdi, i_slope, i_trade5, i_tier)], check.names = FALSE)
brand_table(claims, "Evidence ledger: every claim, its size and how well it survives", 3)
Evidence ledger: every claim, its size and how well it survives
Claim Estimate p (classical) p (HAC) Strength
High-FDI years sit at a different level than Low-FDI years of the same GDP +3.62 pp 0.045 0.088 Fragile
The GDP effect (slope) differs between FDI regimes −1.09 pp per +10% GDP 0.251 0.049 Fragile
High-trade years sit at a different level, once FDI regime is controlled +5.55 pp 0.002 < 0.001 Robust
Industrial structure (three tiers) shifts the line beyond GDP – 0.157 0.115 No clear evidence
Show R code
v2_text <- if (f_slope_inc$p >= 0.05) {
  paste0("No clear evidence (the extra-tilt test gives ", ptxt(f_slope_inc$p), ")")
} else paste0("Some evidence (the extra-tilt test gives ", ptxt(f_slope_inc$p), ")")
trade_phrase <- switch(hac_tab$Strength[i_trade5],
  "Robust" = "it holds under both ordinary and autocorrelation-robust standard errors",
  "Fragile" = "it holds under only one of the two kinds of standard errors",
  "Weak" = "it is only weakly supported", "there is no clear evidence for it")
ImportantVerdict
  1. Does the FDI regime shift Sudan’s renewable share? At equal GDP, High-FDI years sit about 3.6 pp higher (a range of 3.3 to 5.0 pp across cut-offs). The direction is stable, but the evidence is “fragile”: it needs ordinary standard errors and a favourable cut-off to reach 5% significance.
  2. Does FDI change how GDP matters? No clear evidence (the extra-tilt test gives p = 0.251), and Model 3, the only model built to test it without the level shift, is not even stable to the choice of origin.
  3. Does trade openness matter? The trade-openness regime puts years 5.55 pp higher at equal GDP and FDI regime; it holds under both ordinary and autocorrelation-robust standard errors, and the model containing it is the best-fitting one (M5).
  4. Industrial structure: no clear evidence that the three tiers shift the line beyond GDP.

Everything above is an association in 27 annual, autocorrelated observations. It does not show that FDI or trade causes the renewable share to move.

8 Check your understanding

At the same GDP, years with above-median FDI had a renewable share 3.62 pp higher than other years. It is a comparison between groups of years at a fixed GDP, not what happens to Sudan if FDI rises by one unit.

Because the uncentred intercept describes a Sudan with GDP = USD 1 bn (it would be 192.7% of renewable energy, and the dummy would claim a gap of 47.7 pp). Centring moves the reference point to Sudan’s typical GDP (about USD 46.0 bn) without changing the fit.

The joint test spends two parameters. The tilt term adds little (p = 0.251), so it dilutes the evidence carried by the level shift. In a small sample, every extra parameter costs power.

The three dummies sum to 1, which equals the intercept column: perfect collinearity (the dummy-variable trap). With m categories, use m − 1 dummies.

Both are right, for different questions. The raw gap compares averages of two groups that also differ in GDP. Model 2 compares years of equal GDP. The difference is exactly −2.98 pp, the GDP head-start of High-FDI years multiplied by the GDP slope (see the accounting table in Model 2).

9 Reference guide and workspace

Specification What the dummy coefficient means
\(y=\beta_0+\beta_1D+u\) Exact difference of group averages, \(\bar y_{D=1}-\bar y_{D=0}\)
\(y=\beta_0+\beta_1X+\beta_2D+u\) Vertical gap between parallel lines, the same at every \(X\)
\(y=\beta_0+\beta_1X+\beta_2D+\beta_3(XD)+u\) The gap is \(\beta_2+\beta_3X\) and changes with X; \(\beta_2\) is the gap at \(X=0\) (so centre \(X\) first)
Factor with \(m\) categories + intercept \(m-1\) coefficients, each a shift vs the omitted reference group

Always report: the reference category, how the groups were built (and that the cut-off is a choice), the F-test of the joint restriction, and a robustness check for autocorrelated errors.

Show R code
udaje10 <- df_clean
save(udaje10, m_base, m_int, m_slope, m_inter, m_dual, m_poly, models,
     file = "pamat_cvicenie10.Rdata")
cat("Saved Exercise 9b models and data (N =", nrow(udaje10), ") to pamat_cvicenie10.Rdata.")
Saved Exercise 9b models and data (N = 27 ) to pamat_cvicenie10.Rdata.