Skip to main content
v2026.11,986 entries · CC-BY 4.0

Log Regression Stata: Fit and Interpret Log Models

Fit logged-variable models in Stata, interpret proportional changes, and distinguish exponentiated predictions from arithmetic means.

Written and maintained by CASRAI Editorial Board

Published

On this page

To fit log regression in Stata, create the natural logarithm of the outcome, a predictor, or both, then use regress with those variables. The important next step is checking which scale the coefficients and predictions describe: a fitted log outcome is not automatically an arithmetic-mean prediction in the original units.

What Stata is used for in research

Stata’s regress command estimates ordinary least-squares linear models. Logging a variable changes the model specification rather than selecting a separate estimation command. The official regress reference documents the dependent-variable-first syntax used throughout this guide.

Write the intended relationship before building variables. A log-linear model has ln(y) on the left and x on the right. A linear-log model keeps y in its original units and uses ln(x) as a predictor. A log-log model transforms both. Additional predictors may remain untransformed, so each coefficient needs an interpretation tied to its own variable and the outcome’s scale.

For a researcher, the useful question is what comparison the model should answer. Does an additional unit of x correspond to a multiplicative difference in y, or should a proportional difference in x correspond to an additive difference in y? Those are different questions even when the same dataset supplies both variables. The data table below connects each specification to its Stata command and the scale of its default prediction.

A binary-outcome analysis belongs to the separate Stata logistic-regression workflow. For ordinary model syntax and reporting beyond transformations, use the general regression-in-Stata guide.

How to install or access Stata

Use Stata’s installation guide for downloads, installation and license setup. Before installing, have the License and Activation Key available and identify the edition it specifies: MP, SE or BE. If an .stcodes file was supplied, save it for import during installation. The official guide provides separate Windows and Mac instructions and a Unix/Linux installation PDF.

For this analysis, keep the installation task separate from the model specification. Write down the edition and release used alongside the analysis script, then keep the same transformation definitions when sharing the project. A collaborator should be able to identify exactly which columns were logged without reconstructing decisions from a coefficient table. The Stata do-file workflow guide provides a place to organize those commands.

How to fit log regression in Stata step by step

The following commands assume numeric variables named y and x are already in memory. Substitute the actual variable names from your dataset. Keep the original columns so that the transformed model can be checked against the original measurements.

  1. Inspect the variables. Run summarize y x and examine their ranges. The Stata mathematical-functions reference defines ln() for positive values. A variable containing zero or negative values cannot be logged unchanged across all its observations.
  2. Create the required transformation. For a logged outcome, run generate lny = ln(y). For a logged predictor, run generate lnx = ln(x). Stata’s log() is another name for the natural logarithm; log10() explicitly requests base ten.
  3. Fit the specification you intended. Use regress lny x for log-linear, regress y lnx for linear-log, or regress lny lnx for log-log. Choose one for the analysis at hand rather than treating the three commands as interchangeable checks on the same parameter.
  4. Read the sample size and dependent-variable label. Record the reported number of observations and confirm that the coefficient table names the intended outcome. If the result says lny, its coefficients describe that transformed outcome. Resolve unexpected exclusions before interpreting an apparently strong result.
  5. Obtain predictions on the fitted scale. Immediately after the chosen regression, run predict log_fit if e(sample), xb when the outcome is logged. The postestimation reference defines xb as the linear prediction; the sample condition explicitly restricts the new variable to estimation observations.
  6. Retain residuals for examination. Run predict log_residual if e(sample), residuals after the same logged-outcome fit. Keep names that identify the scale. For a linear-log model, use names such as y_fit and y_residual instead, because its outcome remains untransformed.

Before moving to interpretation, make a short audit record: the outcome column, the predictor columns, which were logged, the log base and the estimation sample size. This is an editorial check on the analysis, not an extra statistical test. It makes a later contradiction visible—for example, a table headed “response units” beside a model whose dependent variable was ln(y).

How to read the output

Start with the dependent-variable scale. A coefficient from regress lny x is a change in expected ln(y), conditional on the included predictors. UCLA’s official interpretation guide explains the corresponding geometric-mean ratios and the distinctions between logging the outcome, predictors or both.

A calculated example with six observations

This is an illustrative composite with synthetic numbers, not observations from a study. Define x as 0, 1, 2, 3, 4 and 5. Define a synthetic residual u as 0.1, −0.1, 0, 0, −0.1 and 0.1, respectively. Construct each response using y = exp(ln(10) + 0.2x + u). The values below are rounded for display; the calculation uses the defining expression.

x Synthetic y ln(y)
0 11.051709 2.402585
1 11.051709 2.402585
2 14.918247 2.702585
3 18.221188 2.902585
4 20.137527 3.002585
5 30.041660 3.402585

With those variables loaded, generate lny = ln(y) followed by regress lny x gives the fitted equation ln(ŷ) = 2.302585 + 0.200000x. The residuals sum to zero and their products with x also sum to zero, so the constructed intercept and slope are recovered by ordinary least squares. The residual sum of squares is 0.04; with six observations and two estimated coefficients, the residual mean square is 0.04/4 = 0.01 and Root MSE is 0.1.

The total sum of squares on the log scale is 0.74. Consequently R-squared is 1 − 0.04/0.74 = 0.945946. That calculation uses ln(y), not y. It would be misleading to label this number as the proportion of original-response variation explained without doing a separate original-scale calculation.

For a one-unit increase in x, the fitted geometric-mean ratio is exp(0.2) = 1.221403. Subtracting one and multiplying by 100 gives 22.1403%. A two-unit increase uses exp(2 × 0.2), giving 49.1825%, rather than doubling the one-unit percentage. For this synthetic exercise, report the comparison explicitly: “A one-unit increase in x corresponds to a 22.14% higher fitted geometric mean of y.” This describes the constructed relationship; it is not evidence of a causal effect.

The same coefficient number would mean something else in another specification. If a log-log model had slope 0.2, a 10% increase in x would imply a fitted geometric-mean change of 100 × (1.10.2 − 1) = 1.92449%. If a linear-log model had slope 0.2, that same predictor change would imply 0.2 × ln(1.1) = 0.019062 response units. These are alternative hypothetical models, not three results from the six-row fit.

Prediction in the original units

At x = 3, the example’s fitted log value is 2.902585 and its exponential is 18.221188. Stata’s log-transformed-outcomes tutorial explains why exponentiating a fitted log value alone does not estimate the conditional arithmetic mean.

Under normally distributed errors independent of the covariates, the tutorial uses exp(xb) × exp(σ²/2). In the synthetic arithmetic, substituting the estimated residual variance 0.01 gives 18.221188 × exp(0.01/2) = 18.312522. This illustrates the correction’s size; six invented residuals do not establish its distributional assumptions.

For a log-outcome regression, a point-prediction command following Stata’s documented expression is generate mean_fit = exp(log_fit)*exp((e(rmse)^2)/2). Do not carry that expression into uncertainty calculations blindly: the tutorial warns that a naive margins calculation treating the estimated RMSE as known gives incorrect standard errors. Its worked alternative uses gsem to estimate the error variance jointly before calculating margins.

Troubleshooting Stata

Check the transformation, sample and prediction scale before changing the estimator. These checks help distinguish an unexpected calculation from a model answering a different question.

Zero, negative or missing values

Inspect every variable you intend to log against the positive domain of ln(). An added constant changes the transformation: ln(y + 1) is a different column from ln(y). Document such a choice rather than silently describing both as “log y.” The wider guide to data transformations discusses the implications of these choices.

For example, a hypothetical response of zero is outside the ordinary logarithm’s domain, while a response of one has natural log zero. Confusing those cases reverses the check: a zero in the transformed column can be perfectly legitimate. Inspect the original measurement beside its transformation instead of deleting every transformed zero.

Log base also matters when reversing predictions. Expressing the synthetic outcome in base ten would rescale its slope to 0.2/ln(10) = 0.086859. Reversing that fitted value requires 10 raised to the prediction, rather than exp(prediction). Record the base instead of assuming that every column called “log” was constructed identically.

Residual variation and prediction scope

Stata documents estat hettest after ordinary regress for testing heteroskedasticity. Logging is not a substitute for examining residual behavior. The regression manual also documents vce(robust); using it addresses standard-error estimation rather than supplying the independent normal errors required by the arithmetic-mean correction above.

The postestimation manual makes predictions available outside the estimation sample for unstarred statistics such as xb. Keep if e(sample) when the purpose is checking the fitted observations. Also verify that the active model is the one whose predictions you want: a second model in the script should not quietly supply predictions for the first model’s report.

A report that preserves the scale

As an editorial reporting checklist, retain the exact model equation, transformation definitions, sample size, coefficient and uncertainty interval, and the comparison expressed in reader-facing units. Name the prediction target separately. In the synthetic example, “predicted response” would conceal the distinction between 18.221188 and the assumption-dependent corrected value 18.312522; “exponentiated fitted log response” and “corrected arithmetic-mean prediction” make that choice visible.

Free alternatives to Stata

R and Python’s statsmodels provide alternative linear-model workflows. Reproduce the transformation and estimation sample before comparing their results with Stata. Similar-looking coefficient tables do not establish that the same columns, intercept and observations were used.

Tool Equivalent starting point Check when transferring the analysis
R lm(lny ~ x, data = d) for a previously created log-outcome column The official lm documentation specifies an implied intercept and configurable missing-data handling.
Python with statsmodels sm.OLS(lny, X).fit() with a prepared predictor matrix The array interface does not add an intercept; construct it explicitly, for example with sm.add_constant(X). Set missing-data handling deliberately.

The R lm reference documents summaries and accessors for coefficients, fitted values and residuals. The statsmodels OLS reference documents its response/predictor inputs and missing-value options. In either environment, a model fitted to lny still requires the same distinction between a log-scale prediction and an arithmetic-mean prediction of y.

Sources

Data: Stata log-model commands and prediction scales

Original crosswalk compiled from Stata mathematical-function, regression and postestimation documentation and UCLA interpretation guidance. Commands assume separately generated lny=ln(y) and lnx=ln(x); contrasts hold other predictors fixed and have no interactions.

Stata log-model commands and prediction scales
SpecificationStata fitting commandDefault xb prediction scaleOriginal-scale contrastInterpretation source
Log-linearregress lny xln(y)exp(b*Δx): fitted geometric-mean ratio for change Δx in xUCLA OARC; Stata regress, predict and mathematical functions
Linear-logregress y lnxyb*ln(r): response-unit difference when positive x is multiplied by rUCLA OARC; Stata regress, predict and mathematical functions
Log-logregress lny lnxln(y)r^b: fitted geometric-mean ratio when positive x is multiplied by rUCLA OARC; Stata regress, predict and mathematical functions

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about Log Regression Stata: Fit and Interpret Log Models

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →