Stata Missing Values: 12 Mistakes That Can Ruin Your Analysis
By Siddharth Gupta, independent data consultant and dissertation expert | Last updated: 31 October 2026 | Written for Stata 14 and later
Stata missing values are one of the quietest ways to ruin a dissertation analysis.
Stata gives no warning, so the regression runs, the tables look tidy and the damage stays hidden in your sample size. In my 12 years of guiding dissertation students, how missing data was handled has been one of the most common reasons behind “my results look wrong” queries. If your results already look odd, start with my troubleshooting checklist for results that look wrong.
The 12 Mistakes at a Glance
- Starting the analysis without an audit
- Forgetting that missing is larger than any number
- Creating dummies that tag missing as 1
- Testing with
== .instead ofmissing() - Overlooking missing text values
- Leaving -99 or 999 codes in the data
- Replacing missing values with zero
- Filling gaps with the mean
- Letting row functions treat missing as zero
- Dropping rows without checking who you remove
- Not noticing that your sample changed
- Assuming randomness and not writing down your choice
Mistakes 1 to 4, 10, 11 and the imputation example use Stata’s built-in auto dataset (sysuse auto, clear), so you can reproduce them, while the other examples use illustrative variable names such as income and q1 to q3.
What Are Stata Missing Values?
Stata missing values are placeholders for absent data: a dot (.) or an extended code (.a to .z) for numeric variables, and an empty string ("") for text variables.
That gives 27 numeric missing codes in total, and Stata stores each one as a number larger than any real number, in the order . then .a up to .z. That single fact explains several mistakes below, so learn how Stata missing values behave before you clean, drop or impute anything.
How to Check Missing Values in Stata: 4 Common Mistakes
To check missing values in Stata, run misstable summarize for counts per variable, misstable patterns to see which variables go missing together, and count if missing(varname) for a single variable. Do this before any regression, because every later decision depends on how much is missing and where.
- Run
misstable summarizeto see missing counts for each numeric variable. - Run
misstable patternsto see which variables go missing together. - Run
count if missing(varname)for text variables, becausemisstablefocuses on numeric ones. - Compare the counts with your total N before you build any model.
Mistake 1: Starting the analysis without an audit
Many students run regress first and look at missing data later, if ever, so please reverse that order. Treat Stata missing values as a data quality question first and a modelling question later.
sysuse auto, clear
misstable summarize
misstable patterns
count if missing(rep78)In the auto dataset, rep78 (repair record) has 5 missing values out of 74 cars. The misstable summarize output reports the plain dot and the extended codes in separate columns, so you can see at once if someone used coded missing values.
Mistake 2: Forgetting that missing is larger than any number
count if rep78 > 3
count if rep78 > 3 & !missing(rep78)The first command returns 34 and the second returns 29, and the extra 5 are the cars with missing rep78, because . counts as greater than 3. This is the most common of the Stata missing values traps in conditions.
Mistake 3: Creating dummies that tag missing as 1
gen goodrepair = rep78 > 3
gen goodrepair2 = rep78 > 3 if !missing(rep78)
tabulate goodrepair, missing
tabulate goodrepair2, missingThe first table puts 34 cars in the “good repair” group because it counts the 5 cars with missing rep78, while the second shows 29 cars and lists the 5 missing cars on their own row. A dummy built without the if !missing() condition quietly moves every missing case into the group coded 1.
Mistake 4: Testing with == . instead of missing()
The command count if rep78 == . counts only the plain dot, so if a colleague coded “refused” as .a, that command would skip those rows. The command count if missing(rep78) catches every missing code, and it works on text variables too.
Missing Text and Coded Values: Clean Before You Count
Mistake 5: Overlooking missing text values
In a text variable, missing means "", so a single space or the word “NA” is not missing for Stata.
replace city = strtrim(city)
replace city = "" if city == "NA"
count if missing(city)Excel and survey exports are the usual source of this problem, and Stata missing values in text variables need this extra cleaning step before any count can be trusted.
Mistake 6: Leaving -99 or 999 codes in the data
Survey tools often use -99 for “refused” or 999 for “not applicable”, and Stata reads these as real numbers that pull your mean and regression line. Codes like these are Stata missing values in disguise.
mvdecode q1-q10, mv(-99 = .a \ 999 = .b)Using different extended codes keeps the reason for missingness, and public or secondary datasets use such codes often, so read the codebook first, as I explain in primary vs secondary data for a dissertation. If recoding is new to you, my beginner guide to data transformation in Stata covers the basics.
Stata Replace Missing Values with Zero (and Two Similar Mistakes)
In most cases, you should not replace missing values with zero in Stata, because zero is a real value while missing means unknown. The swap changes means, slopes and standard errors without any statistical reason.
Mistake 7: Replacing missing with zero
replace income = 0 if missing(income)This line looks tidy and is nearly always wrong. Take 100 respondents where 20 skipped the income question and the 80 who answered earn 50,000 on average, and then replace the 20 blanks with zero, which makes the mean fall to 40,000, a 20 per cent drop that does not exist in your population.
Zero is acceptable only when zero is genuinely the answer, such as “number of children” after a skip pattern, and you should write that reason in your do-file.
Mistake 8: Filling gaps with the mean
quietly summarize income
replace income = r(mean) if missing(income)Filling Stata missing values with the mean keeps your N up but shrinks the variance, so standard errors become too small and p-values look better than they deserve. If you must impute, use mi impute chained and report it properly (a short example is further below).
Mistake 9: Letting row functions treat missing as zero
egen total = rowtotal(q1 q2 q3)
gen total2 = q1 + q2 + q3The function rowtotal() adds the available items and treats missing as zero, so a person who answered only one question gets a low score, while q1 + q2 + q3 returns missing if any item is missing. Choose deliberately between the two, and use egen answered = rownonmiss(q1 q2 q3) to see how many items each person answered.
How to Drop Missing Observations in Stata Without Biasing Results
To drop missing observations in Stata, use drop if missing(varname) for one variable. For several variables, create a count with egen nmiss = rowmiss(y x1 x2) and then run drop if nmiss > 0, but only after you have checked who is being removed and saved a backup copy.
Mistake 10: Dropping rows without checking who you remove
save "before_drop.dta", replace
drop if missing(rep78)This is one line, yet it changes your data for the whole session, and if the cars with missing repair records differ from the rest, dropping them changes who your study is about. Compare the two groups before you drop anything, using the code below.
gen byte hasrep = !missing(rep78)
tabulate hasrep foreign, row chi2In survey data the same thing happens when low earners skip the income question more often than others. If the groups differ clearly, say so in your limitations, because rows are easy to drop and hard to bring back.
Missing Values in Stata Regression: The Shrinking Sample Problem
Stata regression commands such as regress and logit drop any row that has a missing value in any model variable, which is called listwise deletion. After every model, check the N in the output or run count if e(sample), so you know how many observations the model actually used.
Mistake 11: Not noticing that your sample changed
sysuse auto, clear
regress price mpg
regress price mpg rep78
count if e(sample)The first model uses 74 cars and the second uses 69, because 5 cars have missing rep78. Both tables look equally neat, which is the problem, since Stata missing values in any one model variable remove that entire row.
To keep model comparisons fair, fit the fuller model first and reuse its sample for the smaller one, as shown below.
regress price mpg rep78
gen byte touse = e(sample)
regress price mpg if touseNow both models use the same 69 cars, and comparisons by R-squared or a likelihood-ratio test are valid only on the same sample. If your output keeps showing different Ns, read my note on different sample sizes in statistical output.
Once N shrinks, recheck your power with my sample size calculator, and then continue with regression diagnostics such as the variance inflation factor.
Stata Missing Data Analysis: Justify Every Decision
Stata missing data analysis starts with one question, which is why the data is missing. Your answer decides whether complete-case analysis, multiple imputation or a sensitivity check is defensible, and the software cannot answer it for you, so write your reasoning down.
Mistake 12: Assuming randomness and not writing down your choice
Rubin’s 1976 paper set up the framework, including missing at random and ignorability, and the labels MCAR, MAR and MNAR became standard through the Little and Rubin textbook. In simple words, the three labels mean the following.
- MCAR: missingness is unrelated to any data, observed or not.
- MAR: missingness is related only to variables you observed.
- MNAR: missingness depends on the missing value itself, such as high earners hiding income.
Students often quote these labels as if naming a type proves it, but MAR cannot be confirmed from your data because the missing values are exactly what you do not have.
In Stata, Little’s MCAR test is available through the user-written mcartest command, which is described in Cheng Li’s Stata Journal article and implements the test for quantitative variables. The same article notes that the test is not suitable for categorical variables, which makes it a weak fit for Likert-type survey items. It can reject MCAR, but a non-rejection in a small sample proves very little.
What the research says, and my view:
- Rubin (1976): The foundation, and still the right vocabulary. The paper gives conditions under which you may ignore the missing data process, but those conditions describe what is true and not what you can test, so in student work they should be stated as assumptions and never as findings.
- Schafer and Graham (2002): They present multiple imputation and maximum likelihood as the state of the art and warn that unsound practice still abounds. I agree with the direction, but they assume you can build a good imputation model, and with 150 respondents and few related variables, a weak imputation can look more rigorous than it is.
- Sterne et al. (BMJ, 2009): A useful account of imputation pitfalls, with guidelines for conduct and reporting. I like the stress on transparency, but what I miss is guidance for small student datasets, since the setting is large epidemiological and clinical research.
- White, Royston and Wood (2011): Sound practical guidance on chained equations, with Stata code fragments. For students, I would add one thing, which is to run the complete-case analysis next to the imputed one so your examiner can see if the conclusion survives.
- UCLA OARC seminar on multiple imputation in Stata: It states plainly that complete-case analysis can give biased estimates under MAR or MNAR, and that modern methods assume at least MAR. That is honest and useful, but its example uses a small, clean teaching dataset, so a student with 30 messy survey items needs more care than the seminar shows.
- Stata manual, misstable and the multiple-imputation manual: Accurate and complete, but written as reference text. A first-time dissertation student needs worked decisions and not only syntax, and that gap is why I wrote this article.
My practical rule is to run complete-case analysis as your baseline, add multiple imputation if the pattern suggests the data is MAR, and report both when they differ. Whichever route you choose, your treatment of Stata missing values must be justified in writing.
Related Missing Data Tasks in Stata
How to count missing values in all variables
foreach v of varlist _all {
quietly count if missing(`v')
display "`v': " r(N)
}This loop covers text and numeric variables together, which misstable summarize does not do by default.
Show missing values inside a table
The command tabulate rep78, missing adds a row for missing values, whereas tabulate without the missing option silently leaves them out and your percentages use a smaller base.
Convert missing back to a code with mvencode
The command mvencode price, mv(-99) turns missing values into -99, and you should use it only when you must export data to software that needs codes.
Missing values after merge or append
After merge 1:1 id using other.dta, run tabulate _merge, because unmatched rows carry missing values for the variables that come from the other file. After append, variables that are absent in one file are missing for the rows that came from it.
Missing values in panel data
Run xtset id year and then xtdescribe to see which participants are missing which waves, since dropout over time is attrition, which I discuss in cross-sectional vs longitudinal design. Classical repeated-measures ANOVA needs complete data per participant, so one missing time point can remove the whole person, and paired t-test vs repeated-measures ANOVA explains the alternatives.
Listwise vs pairwise deletion
The command correlate uses listwise deletion, so every coefficient rests on the same rows, while pwcorr uses pairwise deletion, so each coefficient can rest on a different N. If you use pwcorr, add the obs option and report those Ns.
How much missing data is too much?
I do not give a fixed percentage, because the pattern matters more than the share. Even 5 per cent missing can bias results if it all comes from one group, while a larger share spread evenly may be tolerable. Rules of thumb with fixed cut-offs circulate widely, but none replaces checking the pattern and justifying your choice.
A short multiple imputation example
sysuse auto, clear
mi set mlong
mi register imputed rep78
mi impute chained (ologit) rep78 = price mpg, add(20) rseed(2026)
mi estimate: regress price mpg i.rep78This example shows the syntax only, because a real imputation model needs thought and every predictor you include must be justified.
A 5-Step Audit for Stata Missing Values
- Save the raw file under a new name before any
droporreplace. - Recode codes like -99 and text like “NA” using
mvdecodeandreplace. - Run
misstable summarizeandmisstable patterns. - Compare cases with and without missing data on key variables.
- Choose a treatment, justify it in one sentence, and record it in your do-file.
| Situation | Reasonable treatment | What to write |
|---|---|---|
| Small amount missing, no pattern found | Complete-case analysis | Per cent missing per variable, pattern check |
| Clear pattern linked to other variables | Multiple imputation, compared with complete-case | Imputation model, number of imputations, sensitivity check |
| Zero is a true answer by design | Recode to zero | The skip rule that makes zero correct |
Here is a starter do-file that you can copy and edit.
* Missing data audit (written for Stata 14 and later)
use "yourdata.dta", clear
save "before_cleaning.dta", replace
* Recode sentinel codes and text placeholders (edit names)
* mvdecode q1-q10, mv(-99 = .a \ 999 = .b)
* replace city = strtrim(city)
* replace city = "" if city == "NA"
* Count missing in every variable
foreach v of varlist _all {
quietly count if missing(`v')
display "`v': " r(N)
}
misstable summarize
misstable patterns
* After each model, check the sample used
* regress y x1 x2
* count if e(sample)Follow this routine and your Stata missing values decisions will survive an examiner’s questions.
How to Report Stata Missing Values in a Dissertation
Report the percentage missing for each variable, how you checked the pattern, what treatment you used and why, and one sensitivity check, and put all of this in your methodology chapter before the results. If your university calls it a dissertation or a thesis, the reporting logic is the same, and the Stata commands do not change.
What to write in your methodology chapter
Even if your supervisor has not asked about missing data, your examiner may, so keep a paragraph like the template below ready, and edit it to match what you actually found.
My guide on the quantitative methodology chapter shows where this paragraph fits.
What examiners usually ask
Be ready for questions like these.
- How much data was missing, and in which variables?
- Why did you choose this treatment over the alternatives?
- Did your conclusions change when you handled the missing data differently?
A short justification checklist
- I have counted missing values for every analysis variable.
- I have recoded codes such as -99 and text such as “NA”.
- I have compared complete and incomplete cases.
- I can state why my treatment suits the likely missingness mechanism.
- I have run at least one sensitivity check.
When to Get Expert Help with Stata Data Cleaning
If you have many variables with gaps, panel or survey data, or an examiner who has already questioned your handling, a second pair of eyes saves weeks. AI-written Stata code can also hide these traps, for example by using == . or by replacing missing with zero without saying so, and my guide on how to verify AI-generated dissertation analysis shows what to check.
Not sure if your analysis needs expert eyes? Read how to know if you need a dissertation expert.
Use the five-step audit and copy-ready starter do-file above to review your dataset before your next supervisor meeting.
Frequently Asked Questions
How do I check for missing values in Stata?
Use misstable summarize for counts per variable, misstable patterns for combinations, and count if missing(varname) for one variable. These three commands give a full picture of Stata missing values before you run any model.
How do I count missing values in Stata?
Run count if missing(varname) for one variable. For every variable at once, loop over varlist _all with `count if missing(v’)“, as shown in the related tasks section above.
What Does a Dot Mean in Stata, and Is It Larger Than Any Number?
A dot is Stata’s default numeric missing value, and yes, it is treated as larger than any real number, so a condition like age > 60 also selects rows where age is missing. Add & !missing(age) to avoid this.
What Is the Difference Between a Dot and .a in Stata?
Both are numeric missing values, but .a to .z are 26 extended codes that let you record why a value is missing. The missing() function catches all of them, while == . catches only the plain dot.
How do I drop missing observations in Stata?
Use drop if missing(varname) for one variable, or egen nmiss = rowmiss(y x1 x2) followed by drop if nmiss > 0 for several. Check the pattern first and save a backup file.
Should I replace missing values with zero in Stata?
Usually no, because zero is a real value and it pulls down means and distorts regression results. Do it only when zero is the true answer by design, and document why.
How does Stata handle missing data in regression?
Commands such as regress and logit use listwise deletion, so one missing value in any model variable removes that row. Run count if e(sample) to confirm how many observations the model used.
What is the best way to deal with missing data?
There is no single best method, so first find out why the data is missing, then choose complete-case analysis, multiple imputation or both, and justify the choice. A sensitivity check strengthens whichever route you pick.
How should I handle missing data in a dissertation?
Audit first, check the pattern, and choose a treatment you can defend. Report the percentage missing per variable, your method, and one sensitivity check in the methodology chapter.
How do I know if my data is missing at random?
You cannot fully confirm it, although comparing complete and incomplete cases on observed variables can show that data is not MCAR. The step from there to MAR rests on subject knowledge and sensitivity analysis.
How much missing data is too much?
There is no safe fixed percentage, because the pattern matters more than the share and a small amount concentrated in one group can bias results. Report the share per variable and justify your treatment.
Final Thoughts
Every choice with Stata missing values (drop, recode, impute or leave) is a statistical decision, and your examiner can ask you to defend it. Keep a clear do-file trail, report what you did, and check your results with and without the treatment.
References
- Rubin, D. B. (1976). Inference and missing data. Biometrika, 63(3), 581-592.
- Little, R. J. A. (1988). A test of missing completely at random for multivariate data with missing values. Journal of the American Statistical Association, 83(404), 1198-1202.
- Little, R. J. A., and Rubin, D. B. (2019). Statistical Analysis with Missing Data (3rd ed.). Wiley.
- Schafer, J. L., and Graham, J. W. (2002). Missing data: our view of the state of the art. Psychological Methods, 7(2), 147-177.
- Sterne, J. A. C., et al. (2009). Multiple imputation for missing data in epidemiological and clinical research: potential and pitfalls. BMJ, 338, b2393.
- White, I. R., Royston, P., and Wood, A. M. (2011). Multiple imputation using chained equations: issues and guidance for practice. Statistics in Medicine, 30(4), 377-399.
- Li, C. (2013). Little’s test of missing completely at random. Stata Journal, 13(4), 795-809.
- StataCorp. misstable: Tabulate missing values and the Multiple-Imputation Reference Manual.
- UCLA OARC. Multiple Imputation in Stata.