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.
You added state fixed effects to your regression. Or industry dummies. Or year-by-state interactions. And now Stata says:
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
1// Increase matsize (SE/MP only — IC max is 800)2set matsize 1100034// Make it permanent5set matsize 11000, permanently67// 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.
#Number between 10 and 11000 (SE/MP) or 800 (IC)permanentlySave setting across Stata sessionsMatsize Limits by Stata Flavor
| Stata Flavor | Default matsize | Maximum matsize |
|---|---|---|
| Stata/IC | 400 | 800 |
| Stata/SE | 400 | 11,000 |
| Stata/MP | 400 | 11,000 |
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
1// Check current matsize2query matsize34// Increase it5set matsize 500067// Now your regression works8regress wage education experience tenure "stata-comment">///9 i.occupation i.industry, robustWhen 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
set matsize 11000// Creates thousands of dummy variablesregress wage education i.firm_id i.year, "stata-comment">/// cluster(firm_id)// Slow, memory-heavy, 11,000 matsize needed// No matsize issue — FE are absorbedreghdfe wage education, "stata-comment">/// absorb(firm_id year) "stata-comment">/// cluster(firm_id)// Fast, clean output, handles singletonsreghdfe to absorb them instead of i. to create dummies.Installing reghdfe
1// Install reghdfe and its dependencies2ssc install reghdfe, replace3ssc install ftools, replace45// Verify installation6which 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.
1// Check current memory allocation2memory34// Increase memory if needed (Stata 14 and earlier)5set memory 4g67// Stata 15+ manages memory automatically8// but you can still check usage:9memoryreghdfe is the better approach.Making matsize Permanent
1// Set permanently — survives restart2set matsize 5000, permanently34// Or add to your profile.do5// (located in your Stata personal ado directory)6// Find it with:7sysdir89// Then edit the profile.do file in the PERSONAL directory10// Add this line:11// set matsize 5000Sytra 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.
Related Guides
- Singleton Observations in reghdfe: What They Are and What to Do
- Stata ‘Convergence Not Achieved’: Causes and Solutions
- Panel Data in Stata: xtreg vs. reghdfe vs. areg
We build practical, reproducible workflows for Stata and R teams working on real empirical research pipelines.