spb/metrika Public
Stata-class statistics, GPU-accelerated by Apple Silicon. Native Swift — no Electron, no Python runtime, no compromises.
Swift 92.4%
HTML 3.3%
R 3%
Shell 1.3%
1<!DOCTYPE html>2<html lang="en">3<head>4<meta charset="utf-8">5<meta name="viewport" content="width=device-width, initial-scale=1">6<title>Metrika — Command Reference</title>7<style>8:root { color-scheme: light dark;9 --accent: #4f8cff; --muted: #7a8199; --border: #d9dce6;10 --code-bg: rgba(120, 130, 180, 0.12); }11@media (prefers-color-scheme: dark) {12 :root { --border: #2c3145; } }13* { box-sizing: border-box; }14body { margin: 0; font: 15px/1.55 -apple-system, "Helvetica Neue", sans-serif;15 display: flex; min-height: 100vh; }16nav { width: 230px; flex-shrink: 0; padding: 24px 18px; overflow-y: auto;17 position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--border); }18nav h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;19 color: var(--muted); margin: 18px 0 6px; }20nav ul { list-style: none; margin: 0; padding: 0; }21nav a { text-decoration: none; color: inherit; }22nav a:hover code { color: var(--accent); }23main { flex: 1; max-width: 760px; padding: 32px 40px 80px; }24h1 { font-size: 28px; margin: 0 0 4px; }25.subtitle { color: var(--muted); margin-bottom: 28px; }26h2.category { font-size: 13px; text-transform: uppercase; letter-spacing: .08em;27 color: var(--muted); border-bottom: 1px solid var(--border);28 padding-bottom: 6px; margin-top: 44px; }29article { margin: 26px 0; }30article h2 { font-size: 20px; margin: 0 0 2px; font-family: ui-monospace, monospace; }31.abbr { font-size: 12px; color: var(--muted); margin-left: 8px; }32pre { background: var(--code-bg); border-radius: 8px; padding: 10px 14px;33 overflow-x: auto; font: 13px ui-monospace, "SF Mono", monospace; }34code { font: 13px ui-monospace, "SF Mono", monospace; }35table { border-collapse: collapse; margin: 8px 0; }36td { padding: 3px 14px 3px 0; vertical-align: top; font-size: 14px; }37td:first-child { font-family: ui-monospace, monospace; white-space: nowrap; }38.notes { color: var(--muted); font-size: 14px; }39footer { color: var(--muted); font-size: 12px; margin-top: 56px;40 border-top: 1px solid var(--border); padding-top: 12px; }41</style>42</head>43<body>44<nav><h3>Data management</h3><ul><li><a href="#use"><code>use</code></a></li><li><a href="#sysuse"><code>sysuse</code></a></li><li><a href="#save"><code>save</code></a></li><li><a href="#clear"><code>clear</code></a></li><li><a href="#describe"><code>describe</code></a></li><li><a href="#list"><code>list</code></a></li><li><a href="#count"><code>count</code></a></li><li><a href="#generate"><code>generate</code></a></li><li><a href="#replace"><code>replace</code></a></li><li><a href="#drop"><code>drop</code></a></li><li><a href="#keep"><code>keep</code></a></li></ul><h3>Descriptive statistics</h3><ul><li><a href="#summarize"><code>summarize</code></a></li><li><a href="#tabulate"><code>tabulate</code></a></li><li><a href="#correlate"><code>correlate</code></a></li></ul><h3>Estimation</h3><ul><li><a href="#regress"><code>regress</code></a></li><li><a href="#logit"><code>logit</code></a></li><li><a href="#probit"><code>probit</code></a></li><li><a href="#poisson"><code>poisson</code></a></li><li><a href="#ivregress"><code>ivregress</code></a></li><li><a href="#xtreg"><code>xtreg</code></a></li></ul><h3>Machine learning</h3><ul><li><a href="#lasso"><code>lasso</code></a></li><li><a href="#elasticnet"><code>elasticnet</code></a></li><li><a href="#boost"><code>boost</code></a></li></ul><h3>Resampling & simulation</h3><ul><li><a href="#bootstrap"><code>bootstrap</code></a></li><li><a href="#bayes"><code>bayes</code></a></li><li><a href="#permute"><code>permute</code></a></li><li><a href="#set"><code>set</code></a></li></ul><h3>Post-estimation</h3><ul><li><a href="#predict"><code>predict</code></a></li><li><a href="#margins"><code>margins</code></a></li></ul><h3>Graphics</h3><ul><li><a href="#scatter"><code>scatter</code></a></li><li><a href="#histogram"><code>histogram</code></a></li><li><a href="#kdensity"><code>kdensity</code></a></li><li><a href="#graph"><code>graph</code></a></li></ul><h3>Panel data</h3><ul><li><a href="#xtset"><code>xtset</code></a></li></ul><h3>Session & scripting</h3><ul><li><a href="#display"><code>display</code></a></li><li><a href="#log"><code>log</code></a></li><li><a href="#help"><code>help</code></a></li></ul><h3>User commands</h3><ul><li><a href="#zscore"><code>zscore</code></a></li></ul></nav>45<main>46<h1>Metrika</h1>47<p class="subtitle">Command reference — Stata-class syntax, GPU-accelerated by Apple Silicon.48Every command follows one grammar:49<code>command [varlist] [if] [in] [, options]</code></p>50<h2 class="category">Data management</h2>51<article id="use"><h2>use</h2><p>Load a dataset into memory. Format is inferred from the extension: .parquet, .csv, .tsv, .json, .arrow, and Stata .dta (formats 117–119).</p><pre>use filename</pre><pre>. use sales.parquet52. use ~/data/panel.dta</pre><p class="notes">Loading goes through DuckDB for columnar formats and a native reader for .dta. The sandboxed app reads user-selected files and its own container.</p></article><article id="sysuse"><h2>sysuse</h2><p>Load a sample dataset shipped with Metrika. Bare `sysuse` lists what is available.</p><pre>sysuse [name]</pre><pre>. sysuse sales53. sysuse mtcars</pre><p class="notes">sales: 200-firm × 5-year panel (revenue, price, region, employees). mtcars: the R classic, with a string model column.</p></article><article id="save"><h2>save</h2><p>Write the working dataset to disk (.parquet, .csv, or Stata .dta format 118).</p><pre>save filename [, replace]</pre><table><tr><td>replace</td><td>overwrite an existing file</td></tr></table><pre>. save results.dta, replace</pre></article><article id="clear"><h2>clear</h2><p>Drop the working dataset from memory.</p><pre>clear</pre></article><article id="describe"><h2>describe<span class="abbr">abbreviation: d</span></h2><p>List variables with their storage types and missing counts.</p><pre>describe</pre></article><article id="list"><h2>list<span class="abbr">abbreviation: l</span></h2><p>Print observations (first 50 shown).</p><pre>list [varlist] [if] [in]</pre><pre>. list revenue price in 1/10</pre></article><article id="count"><h2>count<span class="abbr">abbreviation: cou</span></h2><p>Count observations satisfying a condition.</p><pre>count [if]</pre><pre>. count if revenue > 100 & !missing(price)</pre></article><article id="generate"><h2>generate<span class="abbr">abbreviation: gen</span></h2><p>Create a new variable from an expression. Observations excluded by `if` become missing.</p><pre>generate newvar = expression [if] [in]</pre><pre>. gen log_rev = ln(revenue)54. gen high = revenue > 120 if !missing(revenue)</pre><p class="notes">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.</p></article><article id="replace"><h2>replace</h2><p>Overwrite values of an existing variable; reports the number of real changes.</p><pre>replace varname = expression [if] [in]</pre><pre>. replace flag = 0 if missing(flag)</pre></article><article id="drop"><h2>drop</h2><p>Remove variables, or observations with `if`/`in`.</p><pre>drop varlist | drop if expression | drop in range</pre><pre>. drop temp1 temp255. drop if price < 0</pre></article><article id="keep"><h2>keep</h2><p>Keep only the listed variables, or only observations satisfying a condition.</p><pre>keep varlist | keep if expression | keep in range</pre><pre>. keep in 1/1000</pre></article><h2 class="category">Descriptive statistics</h2>56<article id="summarize"><h2>summarize<span class="abbr">abbreviation: su</span></h2><p>Means, standard deviations, and ranges; `detail` adds percentiles, skewness, and kurtosis (Stata definitions).</p><pre>summarize [varlist] [if] [in] [, detail]</pre><table><tr><td>detail</td><td>percentiles p1–p99, skewness, kurtosis</td></tr></table><pre>. summarize revenue price, detail</pre></article><article id="tabulate"><h2>tabulate<span class="abbr">abbreviation: tab</span></h2><p>One-way frequency table or two-way cross-tabulation with totals.</p><pre>tabulate varname [varname2] [if] [, missing]</pre><table><tr><td>missing</td><td>include missing values as a category</td></tr></table><pre>. tab region57. tabulate region purchase</pre></article><article id="correlate"><h2>correlate<span class="abbr">abbreviation: cor</span></h2><p>Pearson correlation matrix with listwise deletion.</p><pre>correlate [varlist] [if]</pre><pre>. correlate revenue price orders</pre></article><h2 class="category">Estimation</h2>58<article id="regress"><h2>regress<span class="abbr">abbreviation: reg</span></h2><p>Ordinary least squares via LAPACK QR. Factor variables (i.var) expand to indicators; c.a#c.b forms continuous interactions.</p><pre>regress depvar [indepvars] [if] [in] [, robust hc2 hc3 cluster(varname) noconstant level(#)]</pre><table><tr><td>robust</td><td>HC1 heteroskedasticity-consistent SE (Stata's robust)</td></tr><tr><td>hc2 / hc3</td><td>leverage-adjusted sandwich estimators</td></tr><tr><td>cluster(var)</td><td>cluster-robust SE, t on G−1 df</td></tr><tr><td>noconstant</td><td>suppress the intercept</td></tr><tr><td>level(#)</td><td>confidence level, default 95</td></tr></table><pre>. reg log_rev price, robust59. reg log_rev price i.region, cluster(firm_id)60. reg wage c.age#c.age education</pre><p class="notes">Results match R to 1e-10. Listwise deletion is reported explicitly.</p></article><article id="logit"><h2>logit</h2><p>Logistic regression by Fisher scoring; reports LR χ², McFadden pseudo-R², z statistics.</p><pre>logit depvar indepvars [if] [, robust cluster(varname) level(#)]</pre><pre>. logit purchase price, robust</pre></article><article id="probit"><h2>probit</h2><p>Probit regression (normal link), same options as logit.</p><pre>probit depvar indepvars [if] [, robust cluster(varname)]</pre><pre>. probit purchase price</pre></article><article id="poisson"><h2>poisson</h2><p>Poisson regression for counts (log link).</p><pre>poisson depvar indepvars [if] [, robust cluster(varname)]</pre><pre>. poisson orders price, robust</pre></article><article id="ivregress"><h2>ivregress</h2><p>Two-stage least squares. Endogenous regressors and their instruments go in the parenthesized group.</p><pre>ivregress 2sls depvar [exogvars] (endogvars = instruments) [, robust cluster(varname)]</pre><pre>. ivregress 2sls log_rev (price = z1 z2), robust</pre><p class="notes">Residuals come from the original regressors; inference follows Stata's `small` convention (t statistics on N−K df).</p></article><article id="xtreg"><h2>xtreg</h2><p>Panel fixed-effects (within) estimator. Declare the panel with xtset first.</p><pre>xtreg depvar indepvars, fe [cluster(panelvar)]</pre><table><tr><td>fe</td><td>fixed effects (required — the only estimator so far)</td></tr><tr><td>cluster(panelvar)</td><td>panel-clustered SE, t on G−1 df</td></tr></table><pre>. xtset firm_id61. xtreg log_rev price, fe cluster(firm_id)</pre></article><h2 class="category">Machine learning</h2>62<article id="lasso"><h2>lasso</h2><p>L1-penalized linear regression (coordinate descent, glmnet conventions). Selects variables by zeroing coefficients.</p><pre>lasso depvar indepvars, lambda(#)</pre><table><tr><td>lambda(#)</td><td>penalty strength; omit it to see lambda_max for your data</td></tr></table><pre>. lasso log_rev price z1 z2 orders, lambda(0.05)</pre></article><article id="elasticnet"><h2>elasticnet</h2><p>Elastic-net linear regression mixing L1 and L2 penalties.</p><pre>elasticnet depvar indepvars, lambda(#) [alpha(#)]</pre><table><tr><td>alpha(#)</td><td>1 = lasso, 0 = ridge; default 1</td></tr><tr><td>lambda(#)</td><td>penalty strength</td></tr></table><pre>. elasticnet log_rev price z1 z2, alpha(0.4) lambda(0.02)</pre><p class="notes">Matches R glmnet, including its gaussian y-standardization convention (ridge penalties scale with sd of the response).</p></article><article id="boost"><h2>boost</h2><p>Gradient-boosted regression trees (xgboost-style exact greedy, squared loss). Deterministic — no subsampling.</p><pre>boost depvar features, rounds(#) [eta(#) maxdepth(#) lambda(#)]</pre><table><tr><td>rounds(#)</td><td>number of trees</td></tr><tr><td>eta(#)</td><td>learning rate, default 0.3</td></tr><tr><td>maxdepth(#)</td><td>tree depth, default 6</td></tr><tr><td>lambda(#)</td><td>L2 regularization on leaf weights, default 1</td></tr></table><pre>. boost log_rev z1 z2 orders, rounds(100) eta(0.1) maxdepth(3)63. predict yhat</pre><p class="notes">Matches R xgboost predictions on identical settings. Training R² is in-sample — expect it to be optimistic.</p></article><h2 class="category">Resampling & simulation</h2>64<article id="bootstrap"><h2>bootstrap</h2><p>Pairs bootstrap of a regression. Large replication counts run batched on the Apple GPU; results are identical either way for a given seed.</p><pre>bootstrap, reps(#) [seed(#)]: regress depvar indepvars</pre><table><tr><td>reps(#)</td><td>number of replications</td></tr><tr><td>seed(#)</td><td>Philox seed — full reproducibility across CPU and GPU</td></tr></table><pre>. bootstrap, reps(10000) seed(42): reg log_rev price</pre><p class="notes">Replicates are counter-addressable: any subset recomputes identically regardless of chunking or backend. The planner dispatches ≥500 reps to the GPU when available.</p></article><article id="bayes"><h2>bayes</h2><p>Bayesian linear regression by Gibbs sampling: posterior means, standard deviations, and 95% credible intervals.</p><pre>bayes [, mcmcsize(#) burnin(#) seed(#) normalprior(#)]: regress depvar indepvars</pre><table><tr><td>mcmcsize(#)</td><td>posterior draws after burn-in (default 10000)</td></tr><tr><td>burnin(#)</td><td>discarded warm-up iterations (default 2500)</td></tr><tr><td>seed(#)</td><td>Philox seed — chains are exactly reproducible</td></tr><tr><td>normalprior(#)</td><td>prior variance of the N(0, #) coefficient priors (default 10000)</td></tr></table><pre>. bayes, mcmcsize(20000) seed(42): reg log_rev price</pre><p class="notes">Priors: coefficients N(0, normalprior), variance InvGamma(0.01, 0.01) — Stata's bayes defaults. With diffuse priors the posterior reproduces OLS.</p></article><article id="permute"><h2>permute</h2><p>Permutation test: the response is permuted, the model refit, and empirical two-sided p-values reported per coefficient.</p><pre>permute, reps(#) [seed(#)]: regress depvar indepvars</pre><pre>. permute, reps(1000) seed(42): reg log_rev orders</pre></article><article id="set"><h2>set</h2><p>Set session parameters. `set seed` fixes the Philox key used by bootstrap and permute.</p><pre>set seed #</pre><pre>. set seed 42</pre></article><h2 class="category">Post-estimation</h2>65<article id="predict"><h2>predict</h2><p>Generate predictions from the last estimation over all current observations.</p><pre>predict newvar [, xb residuals pr n]</pre><table><tr><td>xb</td><td>linear prediction (default after regress/ivregress)</td></tr><tr><td>residuals</td><td>response residuals</td></tr><tr><td>pr</td><td>predicted probability (default after logit/probit)</td></tr><tr><td>n</td><td>predicted mean count (default after poisson)</td></tr></table><pre>. reg log_rev price66. predict yhat67. predict e, residuals</pre></article><article id="margins"><h2>margins<span class="abbr">abbreviation: marg</span></h2><p>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.</p><pre>margins, dydx(varlist) [level(#)]</pre><pre>. logit purchase price68. margins, dydx(price)</pre><p class="notes">Continuous regressors only for now; factor and interaction terms are rejected with a message.</p></article><h2 class="category">Graphics</h2>69<article id="scatter"><h2>scatter</h2><p>Scatter plot (also available as `graph scatter`). `by()` splits into colored series.</p><pre>scatter yvar xvar [if] [, by(varname)]</pre><pre>. scatter log_rev price, by(region)</pre></article><article id="histogram"><h2>histogram<span class="abbr">abbreviation: hist</span></h2><p>Frequency histogram of one variable (Sturges bins by default).</p><pre>histogram varname [if] [, bins(#)]</pre><table><tr><td>bins(#)</td><td>override the bin count</td></tr></table><pre>. histogram revenue, bins(12)</pre></article><article id="kdensity"><h2>kdensity<span class="abbr">abbreviation: kden</span></h2><p>Kernel density estimate (Epanechnikov kernel, Silverman bandwidth).</p><pre>kdensity varname [if]</pre><pre>. kdensity revenue</pre></article><article id="graph"><h2>graph<span class="abbr">abbreviation: gr</span></h2><p>General plotting front end: graph scatter, graph line, graph histogram.</p><pre>graph scatter|line yvar xvar [if] [, by(varname)]</pre><pre>. graph line gdp year</pre></article><h2 class="category">Panel data</h2>70<article id="xtset"><h2>xtset</h2><p>Declare the panel structure (unit and, optionally, time variable) for xtreg.</p><pre>xtset panelvar [timevar]</pre><pre>. xtset firm_id year</pre></article><h2 class="category">Session & scripting</h2>71<article id="display"><h2>display<span class="abbr">abbreviation: di</span></h2><p>Evaluate and print an expression.</p><pre>display expression</pre><pre>. display 2 + 2 * 372. display ln(100)</pre></article><article id="log"><h2>log</h2><p>Record commands and output to a text file.</p><pre>log using filename | log close</pre><pre>. log using session.log</pre></article><article id="help"><h2>help</h2><p>Show this reference, or the entry for one command.</p><pre>help [command]</pre><pre>. help regress</pre></article><h2 class="category">User commands</h2>73<article id="zscore"><h2>zscore</h2><p>Sample native plugin: generates z_varname, the standardized version of a variable.</p><pre>zscore varname</pre><pre>. zscore revenue</pre><p class="notes">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.</p></article>74<footer>© 2026 Simon-Pierre Boucher. Generated from the in-app command75reference by <code>metrika-cli docs</code>.</footer>76</main>77</body>78</html>