Stata Errors
2026-02-097 min read

Stata 'matsize too small' Error: How to Fix It (and When You Shouldn't)

set matsize is the quick fix. But if you need 11,000 matsize, the real fix is reghdfe. Here's how to tell the difference.

Sytra Team
Research Engineering Team, Sytra AI

You added state fixed effects to your regression. Or industry dummies. Or year-by-state interactions. And now Stata says:

. regress wage education i.state_id i.year i.industry
matsize too small
r(908);

The quick fix is one line. But the right fix depends on why your matsize is too small — and sometimes increasing matsize is exactly the wrong thing to do.

All examples tested in Stata 18 SE. Compatible with Stata 15+.


Quick Answer

quick-fix.do
stata
1// Increase matsize (SE/MP only — IC max is 800)
2set matsize 11000
3
4// Make it permanent
5set matsize 11000, permanently
6
7// If you're hitting matsize because of dummy variables,
8// the real fix is reghdfe:
9reghdfe wage education, absorb(state_id year industry)

What matsize Controls

Matsize sets the maximum number of variables Stata can include in an estimation command’s variance-covariance matrix. Every variable in your regression — including every dummy variable created by factor notation like i.state_id — counts toward this limit.

The default matsize in Stata is 400. If you have a regression with 50 state dummies, 20 year dummies, and 100 industry dummies, that’s already 170+ variables just from fixed effects — plus your actual regressors.

set matsize

Stata docs →

Sets the maximum number of variables in estimation commands.

set matsize # [, permanently]
#Number between 10 and 11000 (SE/MP) or 800 (IC)
permanentlySave setting across Stata sessions

Matsize Limits by Stata Flavor

Stata FlavorDefault matsizeMaximum matsize
Stata/IC400800
Stata/SE40011,000
Stata/MP40011,000
⚠️Stata IC users
If you’re on Stata/IC and need more than 800 variables, you cannot increase matsize further. Your only option is to absorb fixed effects using reghdfe or areg, or upgrade to Stata/SE.

When You Should Increase matsize

Increasing matsize is the right answer when you genuinely need all those variables as separate coefficients in your model — for example:

  • You have many control variables (30+ regressors)
  • You’re running a model with many interaction terms you need to report
  • You need the actual coefficient estimates for each dummy
increase-matsize.do
stata
1// Check current matsize
2query matsize
3
4// Increase it
5set matsize 5000
6
7// Now your regression works
8regress wage education experience tenure "stata-comment">///
9 i.occupation i.industry, robust

When You Should NOT Increase matsize

If you’re hitting matsize because you’re including fixed effects as dummy variables with i.firm_id or i.county_fips, increasing matsize is the wrong fix. The right fix is absorbing the fixed effects.

Why? Including 5,000 firm dummies as explicit variables:

  • Requires Stata to invert a 5,000 × 5,000 matrix — slow and memory-intensive
  • Clutters your output with 5,000 coefficients you don’t care about
  • May hit the 11,000 matsize ceiling with multi-way FE
  • Doesn’t properly handle singleton observations
Wrong — dummy variables
stata
set matsize 11000
// Creates thousands of dummy variables
regress wage education i.firm_id i.year, "stata-comment">///
cluster(firm_id)
// Slow, memory-heavy, 11,000 matsize needed
Right — absorbed FE
stata
// No matsize issue — FE are absorbed
reghdfe wage education, "stata-comment">///
absorb(firm_id year) "stata-comment">///
cluster(firm_id)
// Fast, clean output, handles singletons
💡Rule of thumb
If you don’t need to see the fixed effect coefficients (and you almost never do), use reghdfe to absorb them instead of i. to create dummies.

Installing reghdfe

install-reghdfe.do
stata
1// Install reghdfe and its dependencies
2ssc install reghdfe, replace
3ssc install ftools, replace
4
5// Verify installation
6which reghdfe
. which reghdfe
/Users/username/ado/plus/r/reghdfe.ado
*! version 6.12.3 07nov2023

Memory Implications

Increasing matsize increases memory usage. Stata must allocate memory for an N × K matrix where K is the matsize. At matsize 11,000, this means Stata allocates ~968 MB just for the matrix — before your data.

memory-check.do
stata
1// Check current memory allocation
2memory
3
4// Increase memory if needed (Stata 14 and earlier)
5set memory 4g
6
7// Stata 15+ manages memory automatically
8// but you can still check usage:
9memory
⚠️Watch out
On laptops with 8 GB of RAM, setting matsize to 11,000 with a large dataset may cause Stata to run out of memory. Consider whether you really need all those variables as coefficients, or whether absorbing them with reghdfe is the better approach.

Making matsize Permanent

permanent-matsize.do
stata
1// Set permanently — survives restart
2set matsize 5000, permanently
3
4// Or add to your profile.do
5// (located in your Stata personal ado directory)
6// Find it with:
7sysdir
8
9// Then edit the profile.do file in the PERSONAL directory
10// Add this line:
11// set matsize 5000

Sytra catches these errors before you run.

Sytra automatically uses reghdfe when your model includes fixed effects, so you never hit matsize limits. Describe your model in plain language and Sytra picks the right estimator.

Join the Waitlist →

FAQ

What does matsize too small mean in Stata?

Matsize controls the maximum number of variables Stata can include in an estimation command. When your model has more variables (including dummies from factor variables) than the current matsize allows, Stata throws this error. Increase it with set matsize #.

How do I increase matsize in Stata?

Run set matsize 11000 (or your desired number). The maximum depends on your Stata flavor: IC allows up to 800, SE up to 11,000, and MP up to 11,000. For permanent changes, addset matsize 11000, permanently.

What is the maximum matsize in Stata?

Stata IC: 800. Stata SE: 11,000. Stata MP: 11,000. If you need more than 11,000, you cannot simply increase matsize. Use reghdfe to absorb fixed effects instead of creating dummy variables.

Should I always increase matsize when I get this error?

No. If your matsize needs to be very large (over 2,000), it usually means you are including fixed effects as dummy variables. The better approach is reghdfe, which absorbs fixed effects without creating dummies, making matsize irrelevant.


Written by Sytra Team
Research Engineering Team, Sytra AI

We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.

#Stata#Errors#Memory#Fixed Effects

Enjoyed this article?