Stata Error “type mismatch” — Troubleshooting Guide (NYC)

The Stata error type mismatch appears when you mix string and numeric variables in a command that requires one or the other. This is extremely common in econometrics homework, especially when importing Excel files. For broader graduate statistics and software support, visit our main page: Statistics Tutoring NYC.

Why this error happens

  • A variable looks numeric but is stored as a string.
  • Commas, currency symbols, or text codes prevent numeric storage.
  • You used a string variable in a numeric command (e.g., regress, summarize).
  • You used a numeric variable where Stata expects a string (e.g., if var == "A").

How to diagnose the issue

1. Check the variable type

describe varname

2. Inspect the contents

codebook varname

If you see values like "1,200" or "$500", Stata treats them as strings.

How to fix it

Convert numeric strings to numeric

destring income, replace ignore(",")

Convert categories to numeric

encode group, gen(group_num)

Fix string comparisons

If group is numeric, do not write:

if group == "A"

Use:

if group == 1

Need help?

If you’re unsure whether a variable should be numeric or string, or your dataset is messy, you can get direct help with Stata troubleshooting.

Call or text: 646‑543‑0832
WhatsApp: 206‑384‑1336
Email: tutor@mytutornyc.com