Metrika

Command reference — Stata-class syntax, GPU-accelerated by Apple Silicon. Every command follows one grammar: command [varlist] [if] [in] [, options]

Data management

use

Load a dataset into memory. Format is inferred from the extension: .parquet, .csv, .tsv, .json, .arrow, and Stata .dta (formats 117–119).

use filename
. use sales.parquet
. use ~/data/panel.dta

Loading goes through DuckDB for columnar formats and a native reader for .dta. The sandboxed app reads user-selected files and its own container.

sysuse

Load a sample dataset shipped with Metrika. Bare `sysuse` lists what is available.

sysuse [name]
. sysuse sales
. sysuse mtcars

sales: 200-firm × 5-year panel (revenue, price, region, employees). mtcars: the R classic, with a string model column.

save

Write the working dataset to disk (.parquet, .csv, or Stata .dta format 118).

save filename [, replace]
replaceoverwrite an existing file
. save results.dta, replace

clear

Drop the working dataset from memory.

clear

describeabbreviation: d

List variables with their storage types and missing counts.

describe

listabbreviation: l

Print observations (first 50 shown).

list [varlist] [if] [in]
. list revenue price in 1/10

countabbreviation: cou

Count observations satisfying a condition.

count [if]
. count if revenue > 100 & !missing(price)

generateabbreviation: gen

Create a new variable from an expression. Observations excluded by `if` become missing.

generate newvar = expression [if] [in]
. gen log_rev = ln(revenue)
. gen high = revenue > 120 if !missing(revenue)

Functions: ln, log, log10, exp, sqrt, abs, floor, ceil, round, int, min, max, missing. Missing values propagate through arithmetic; division by zero and ln of a nonpositive number yield missing.

replace

Overwrite values of an existing variable; reports the number of real changes.

replace varname = expression [if] [in]
. replace flag = 0 if missing(flag)

drop

Remove variables, or observations with `if`/`in`.

drop varlist | drop if expression | drop in range
. drop temp1 temp2
. drop if price < 0

keep

Keep only the listed variables, or only observations satisfying a condition.

keep varlist | keep if expression | keep in range
. keep in 1/1000

Descriptive statistics

summarizeabbreviation: su

Means, standard deviations, and ranges; `detail` adds percentiles, skewness, and kurtosis (Stata definitions).

summarize [varlist] [if] [in] [, detail]
detailpercentiles p1–p99, skewness, kurtosis
. summarize revenue price, detail

tabulateabbreviation: tab

One-way frequency table or two-way cross-tabulation with totals.

tabulate varname [varname2] [if] [, missing]
missinginclude missing values as a category
. tab region
. tabulate region purchase

correlateabbreviation: cor

Pearson correlation matrix with listwise deletion.

correlate [varlist] [if]
. correlate revenue price orders

Estimation

regressabbreviation: reg

Ordinary least squares via LAPACK QR. Factor variables (i.var) expand to indicators; c.a#c.b forms continuous interactions.

regress depvar [indepvars] [if] [in] [, robust hc2 hc3 cluster(varname) noconstant level(#)]
robustHC1 heteroskedasticity-consistent SE (Stata's robust)
hc2 / hc3leverage-adjusted sandwich estimators
cluster(var)cluster-robust SE, t on G−1 df
noconstantsuppress the intercept
level(#)confidence level, default 95
. reg log_rev price, robust
. reg log_rev price i.region, cluster(firm_id)
. reg wage c.age#c.age education

Results match R to 1e-10. Listwise deletion is reported explicitly.

logit

Logistic regression by Fisher scoring; reports LR χ², McFadden pseudo-R², z statistics.

logit depvar indepvars [if] [, robust cluster(varname) level(#)]
. logit purchase price, robust

probit

Probit regression (normal link), same options as logit.

probit depvar indepvars [if] [, robust cluster(varname)]
. probit purchase price

poisson

Poisson regression for counts (log link).

poisson depvar indepvars [if] [, robust cluster(varname)]
. poisson orders price, robust

ivregress

Two-stage least squares. Endogenous regressors and their instruments go in the parenthesized group.

ivregress 2sls depvar [exogvars] (endogvars = instruments) [, robust cluster(varname)]
. ivregress 2sls log_rev (price = z1 z2), robust

Residuals come from the original regressors; inference follows Stata's `small` convention (t statistics on N−K df).

xtreg

Panel fixed-effects (within) estimator. Declare the panel with xtset first.

xtreg depvar indepvars, fe [cluster(panelvar)]
fefixed effects (required — the only estimator so far)
cluster(panelvar)panel-clustered SE, t on G−1 df
. xtset firm_id
. xtreg log_rev price, fe cluster(firm_id)

Machine learning

lasso

L1-penalized linear regression (coordinate descent, glmnet conventions). Selects variables by zeroing coefficients.

lasso depvar indepvars, lambda(#)
lambda(#)penalty strength; omit it to see lambda_max for your data
. lasso log_rev price z1 z2 orders, lambda(0.05)

elasticnet

Elastic-net linear regression mixing L1 and L2 penalties.

elasticnet depvar indepvars, lambda(#) [alpha(#)]
alpha(#)1 = lasso, 0 = ridge; default 1
lambda(#)penalty strength
. elasticnet log_rev price z1 z2, alpha(0.4) lambda(0.02)

Matches R glmnet, including its gaussian y-standardization convention (ridge penalties scale with sd of the response).

boost

Gradient-boosted regression trees (xgboost-style exact greedy, squared loss). Deterministic — no subsampling.

boost depvar features, rounds(#) [eta(#) maxdepth(#) lambda(#)]
rounds(#)number of trees
eta(#)learning rate, default 0.3
maxdepth(#)tree depth, default 6
lambda(#)L2 regularization on leaf weights, default 1
. boost log_rev z1 z2 orders, rounds(100) eta(0.1) maxdepth(3)
. predict yhat

Matches R xgboost predictions on identical settings. Training R² is in-sample — expect it to be optimistic.

Resampling & simulation

bootstrap

Pairs bootstrap of a regression. Large replication counts run batched on the Apple GPU; results are identical either way for a given seed.

bootstrap, reps(#) [seed(#)]: regress depvar indepvars
reps(#)number of replications
seed(#)Philox seed — full reproducibility across CPU and GPU
. bootstrap, reps(10000) seed(42): reg log_rev price

Replicates are counter-addressable: any subset recomputes identically regardless of chunking or backend. The planner dispatches ≥500 reps to the GPU when available.

bayes

Bayesian linear regression by Gibbs sampling: posterior means, standard deviations, and 95% credible intervals.

bayes [, mcmcsize(#) burnin(#) seed(#) normalprior(#)]: regress depvar indepvars
mcmcsize(#)posterior draws after burn-in (default 10000)
burnin(#)discarded warm-up iterations (default 2500)
seed(#)Philox seed — chains are exactly reproducible
normalprior(#)prior variance of the N(0, #) coefficient priors (default 10000)
. bayes, mcmcsize(20000) seed(42): reg log_rev price

Priors: coefficients N(0, normalprior), variance InvGamma(0.01, 0.01) — Stata's bayes defaults. With diffuse priors the posterior reproduces OLS.

permute

Permutation test: the response is permuted, the model refit, and empirical two-sided p-values reported per coefficient.

permute, reps(#) [seed(#)]: regress depvar indepvars
. permute, reps(1000) seed(42): reg log_rev orders

set

Set session parameters. `set seed` fixes the Philox key used by bootstrap and permute.

set seed #
. set seed 42

Post-estimation

predict

Generate predictions from the last estimation over all current observations.

predict newvar [, xb residuals pr n]
xblinear prediction (default after regress/ivregress)
residualsresponse residuals
prpredicted probability (default after logit/probit)
npredicted mean count (default after poisson)
. reg log_rev price
. predict yhat
. predict e, residuals

marginsabbreviation: marg

Average marginal effects with delta-method standard errors. After OLS/IV the effect is the coefficient; after logit/probit/poisson it averages dμ/dx over the estimation sample.

margins, dydx(varlist) [level(#)]
. logit purchase price
. margins, dydx(price)

Continuous regressors only for now; factor and interaction terms are rejected with a message.

Graphics

scatter

Scatter plot (also available as `graph scatter`). `by()` splits into colored series.

scatter yvar xvar [if] [, by(varname)]
. scatter log_rev price, by(region)

histogramabbreviation: hist

Frequency histogram of one variable (Sturges bins by default).

histogram varname [if] [, bins(#)]
bins(#)override the bin count
. histogram revenue, bins(12)

kdensityabbreviation: kden

Kernel density estimate (Epanechnikov kernel, Silverman bandwidth).

kdensity varname [if]
. kdensity revenue

graphabbreviation: gr

General plotting front end: graph scatter, graph line, graph histogram.

graph scatter|line yvar xvar [if] [, by(varname)]
. graph line gdp year

Panel data

xtset

Declare the panel structure (unit and, optionally, time variable) for xtreg.

xtset panelvar [timevar]
. xtset firm_id year

Session & scripting

displayabbreviation: di

Evaluate and print an expression.

display expression
. display 2 + 2 * 3
. display ln(100)

log

Record commands and output to a text file.

log using filename | log close
. log using session.log

help

Show this reference, or the entry for one command.

help [command]
. help regress

User commands

zscore

Sample native plugin: generates z_varname, the standardized version of a variable.

zscore varname
. zscore revenue

Native plugins are Swift types conforming to ZQCommandPlugin, compiled into the app. Script commands are .zyq files in ~/Library/Application Support/Metrika/Commands/ — an optional leading `args name…` line names positional arguments, referenced as `name' or `1' in the body.