Component Reference

Every authoring construct available in the lecture notes

Author
Affiliation

Henrique Veras

PIMES/UFPE

This page is the working reference for writing lectures. Each construct below shows the source on the left of the fence and the rendered result immediately after. Nothing here is course content — it exists so that writing Lecture 5 does not require remembering how the Monte Carlo box is spelled.

The page also functions as a smoke test: if it renders correctly, the infrastructure is sound.


1 1. Theorem environments

These replace the screenshots of Greene used in the legacy notes. They are numbered automatically, cross-referenceable, searchable, and accessible.

::: {#thm-demo}
## Frisch-Waugh-Lovell

In the regression $\bY = \bX_1\bbeta_1 + \bX_2\bbeta_2 + \beps$, the OLS estimator
of $\bbeta_2$ is $\bb_2 = (\bX_2'\bM_1\bX_2)^{-1}\bX_2'\bM_1\bY$.
:::

As @thm-demo shows, ...

Theorem 1 (Frisch-Waugh-Lovell) In the regression \(\bY = \bX_1\bbeta_1 + \bX_2\bbeta_2 + \beps\), the OLS estimator of \(\bbeta_2\) is \[\bb_2 = (\bX_2'\bM_1\bX_2)^{-1}\bX_2'\bM_1\bY, \qquad \bM_1 = \bI - \bX_1(\bX_1'\bX_1)^{-1}\bX_1'.\]

Proof. Partition the normal equations and solve the first block for \(\bb_1\). Substituting into the second block and collecting terms gives the stated expression. \(\square\)

As Theorem 1 shows, a multiple regression coefficient is a simple regression coefficient on partialled-out data.

The full family is available: #thm-, #lem-, #cor-, #prp-, #def-, #exm-, #exr-, plus ::: {.proof} and ::: {.remark}.

Definition 1 (Projection matrix) \(\bP = \bX(\bX'\bX)^{-1}\bX'\) is the orthogonal projection onto the column space of \(\bX\).

Corollary 1 (Residual maker) \(\bM = \bI - \bP\) is symmetric, idempotent, and satisfies \(\bM\bX = \bzero\).


2 2. Annotated equations

The construct that carries the most pedagogical weight. Terms inside the display math are tagged with \eqt{key}{...}; the explanations follow as a definition list keyed by the same letters. Hover or click a term — the term and its note highlight together. Click again, or click outside, to release.

::: {.eqnote}
$$
\bb = \bbeta + \eqt{a}{\left(\frac{\bX'\bX}{n}\right)^{-1}}
             \eqt{b}{\left(\frac{\bX'\beps}{n}\right)}
$$

a
:   By assumption A2$'$, this converges in probability to $\bQ^{-1}$.

b
:   By the LLN this converges to $\E[\bX_i\varepsilon_i] = \bzero$.
    **This is the term that carries exogeneity.**
:::

\[ \bb = \bbeta + \eqt{a}{\left(\frac{\bX'\bX}{n}\right)^{-1}} \eqt{b}{\left(\frac{\bX'\beps}{n}\right)} \]

a
By assumption A2\('\), \(\bX'\bX/n \pto \bQ\), a positive definite matrix. The Continuous Mapping Theorem then gives \((\bX'\bX/n)^{-1} \pto \bQ^{-1}\), a finite limit.
b
By the LLN, \(\bX'\beps/n \pto \E[\mathbf{x}_i\varepsilon_i]\). Under A3 this expectation is \(\bzero\). This is the term that carries exogeneity — and the single point at which the whole consistency argument can fail.

Consistency of \(\bb\) is the product of these two limits: a finite matrix times zero.

  • Keys are arbitrary strings (a, b, Q, num). Keep them short — they appear in a circular badge.
  • A \eqt{} with no matching note, or the reverse, produces a render-time warning. Silent dead cards are not possible.
  • In PDF output \eqt{key}{body} degrades to body and the notes become an ordinary list. Nothing is lost.
  • The macro set (\bb, \bX, \beps, \pto, \plim, \E, …) is declared once in assets/mathjax.html. Add to it there rather than redefining per lecture.

3 3. Pedagogical boxes

Seven recurring callouts implementing the narrative architecture. All take an optional title=.

3.1 What is the DGP?

Opens each major topic.

::: {.dgp}
$y_i = \mathbf{x}_i'\bbeta + \varepsilon_i$, with $(y_i, \mathbf{x}_i)$ i.i.d.
:::
What is the DGP?

\(y_i = \mathbf{x}_i'\bbeta + \varepsilon_i\) with \((y_i,\mathbf{x}_i)\) i.i.d. across \(i\), \(\E[\varepsilon_i \mid \mathbf{x}_i] = 0\), and \(\E[\mathbf{x}_i\mathbf{x}_i']\) finite and nonsingular.

Parameter of interest: \(\bbeta\). Is it identified? Yes — full rank plus exogeneity.

3.2 The Four Questions

Precedes each formal result.

The Four Questions—Before Gauss-Markov
  1. What problem are we solving? Many estimators are unbiased. We need a reason to prefer one.
  2. Why does it matter? Without an efficiency criterion, “use OLS” is a convention rather than a result.
  3. What is the idea? Restrict attention to linear unbiased estimators and minimise variance within that class.
  4. How do we formalise it? Show any such estimator has variance exceeding that of OLS by a positive semi-definite matrix.

3.3 Researcher’s Toolbox

Researcher's Toolbox—OLS as an M-estimator

We derived \(\bb\) by minimising \(S(\mathbf{b}) = (\bY - \bX\mathbf{b})'(\bY - \bX\mathbf{b})\). That is an instance of \[\hat\btheta = \argmin_{\btheta} Q_n(\btheta).\] Estimators of this form are M-estimators. Maximum likelihood is another. Keep the shape in mind — it returns in Lecture 13, where it becomes the organising idea rather than an observation.

3.4 Under the Hood

Under the Hood—No software inverts X'X

The textbook formula \(\bb = (\bX'\bX)^{-1}\bX'\bY\) is not what lm() computes. Forming \(\bX'\bX\) squares the condition number, so a design that is merely awkward becomes numerically singular. R uses a QR decomposition instead:

qr_fit <- qr(X)
b <- qr.coef(qr_fit, y)     # no explicit inverse anywhere

This is why near-collinearity is a numerical problem before it is a statistical one — a point we return to in Lecture 9.

3.5 Monte Carlo

Monte Carlo—Seeing consistency

Fix \(\beta = 1\). Draw samples of size \(n\), estimate \(\hat\beta\), repeat 10,000 times, and plot the distribution. As \(n\) grows the distribution concentrates on \(1\) — that is consistency, made visible. Rescale by \(\sqrt{n}\) and it stabilises into a normal curve — that is asymptotic normality.

The simulation proves nothing. It shows what the theorem already established.

3.6 Connection

Connection—The within transformation is FWL again

Demeaning \(y_{it}\) and \(x_{it}\) within each unit is exactly \(\bM_1\) applied to \(\bY\) and \(\bX\), where \(\bX_1\) is the matrix of unit dummies. Fixed effects is not a new estimator — it is Theorem 1 applied to a particular partition.

3.7 On the Board

Marks a derivation worked live on the blackboard. The written proof stays condensed — the structure and the pivotal step — because the steps are supplied in the lecture.

On the Board

Worked on the board. The skeleton:

Proof. Substitute \(\bb_1\) from the first block into the second and collect terms; the projector assembles itself. A2 gives invertibility. \(\square\)

3.8 In the Literature

In the Literature—Angrist & Krueger (1991)

Quarter of birth as an instrument for schooling (Angrist and Krueger 1991). Read it after Lecture 10 and return to it after Lecture 11 — it is also the canonical cautionary tale about weak instruments.


4 4. Standard Quarto constructs

The built-in callouts remain available and are used for mechanics rather than pedagogy.

Note

Administrative information: deadlines, corrections, reading assignments.

Warning

A common error, or a result that does not hold under weaker assumptions.

4.1 Margin content

Side remarks that would break the argument go in the margin.1

Margin note: useful for pointing at the corresponding section of Hansen or Greene without interrupting the flow.

4.2 Code

Code
set.seed(20262)
n <- 200
x <- rnorm(n)
y <- 1 + 2 * x + rnorm(n)
coef(lm(y ~ x))
#> (Intercept)           x 
#>   0.9500911   2.0813428

4.3 Tabsets

b <- qr.solve(X, y)

\[\bb = (\bX'\bX)^{-1}\bX'\bY\]

Form the normal equations \(\bX'\bX\mathbf{b} = \bX'\bY\) and solve the linear system.


5 5. Writing one source for two outputs

Each lecture .qmd renders both as a chapter of the website and as a Reveal.js deck.

Heading levels are the primary control

Level Website Deck
## Section Section divider slide
### Subsection One slide

Write ### units that hold one idea. A ### whose prose runs past roughly 80 words is a slide that will be unreadable from the back of the room — split it.

.longform and .onslide

The real problem is not structure but register: prose that reads well in the notes is unreadable projected on a wall. Two wrappers keep one source serving both.

::: {.longform}
Expository prose — full argument, subordinate clauses, the "why".
Appears in the notes; dropped from the deck.
:::

::: {.onslide}
- Three bullets
- The same point, compressed
Appears in the deck; dropped from the notes.
:::

Content outside either wrapper appears in both — which is where definitions, theorems, boxes, figures and tables normally belong.

The density target

Aim for 40–70 words per slide, and treat anything above 90 as a defect. To measure a deck after rendering:

python3 - <<'EOF'
import re
h = open('_slides/notas/01-map.html').read()
secs = re.findall(r'<section[^>]*>(.*?)</section>', h, re.S)
w = [len(re.sub(r'<[^>]+>', ' ', s).split()) for s in secs]
w = [x for x in w if x > 3]
print(f'slides {len(w)}  mean {sum(w)//len(w)}  worst {max(w)}')
EOF

The explicit form

.longform and .onslide are shorthand. The underlying mechanism is Quarto’s conditional content, and when you need it directly, always key the condition on revealjs:

::: {.content-hidden when-format="revealjs"}
Long-form derivation, shown only in the notes.
:::

::: {.content-visible when-format="revealjs"}
Three bullet points, shown only in the lecture.
:::
Do not write when-format="html" to mean “the website”

Reveal.js is an HTML format, so when-format="html" matches the deck as well and the content leaks into the slides. Only revealjs distinguishes the two reliably:

Intent Correct Wrong
Website only .content-hidden when-format="revealjs" .content-visible when-format="html"
Slides only .content-visible when-format="revealjs" —
Note

You are reading the website version — this paragraph is absent from the slides.

Speaker notes:

Visible in the Reveal.js presenter view (press S), absent from the website.


6 6. Cross-references

Target Syntax Renders
Theorem @thm-demo Theorem 1
Definition @def-projection Definition 1
Corollary @cor-residual-maker Corollary 1
Citation @hansen2022econometrics Hansen (2022)
Section @sec-label —

6.1 References

Angrist, Joshua D., and Alan B. Krueger. 1991. “Does Compulsory School Attendance Affect Schooling and Earnings?” Quarterly Journal of Economics 106 (4): 979–1014.
Hansen, Bruce E. 2022. Econometrics. Princeton, NJ: Princeton University Press.
Back to top

Footnotes

  1. Footnotes work as usual and appear on hover.↩︎