Code Languages Guide for Less Likely

Author

This guide shows how to use Stata, Julia, and pseudocode in your Quarto posts.

Supported Languages

Your site now supports syntax highlighting and execution for:

  • R (via knitr)
  • Python (via Jupyter)
  • Julia (via Jupyter)
  • Stata (via Stata engine)
  • Pseudocode (syntax highlighting only)
  • Observable JS
  • And many more for syntax highlighting only

Stata Code Blocks

Syntax Highlighting Only (No Execution)

* Load data
use "mydata.dta", clear

* Descriptive statistics
summarize age weight height

* Linear regression
regress weight height age

* Save results
estimates store model1

Executed Stata Code (requires Stata installation)

In your post YAML header:

---
title: "My Analysis"
format:
  html:
    code-fold: false
engine: knitr
---

Then in your post:


::: {.cell statapath='/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP'}

```{.stata .cell-code}
* Your Stata code here
sysuse auto
summarize price mpg
regress price mpg weight
```
:::

Stata with RStata Package

For executing Stata from R chunks:


::: {.cell}

```{.stata .cell-code}
sysuse auto
summarize price mpg
```
:::

Julia Code Blocks

Syntax Highlighting Only

# Julia example
using DataFrames, Statistics

# Create a DataFrame
df = DataFrame(
    x = 1:10,
    y = rand(10)
)

# Calculate statistics
mean(df.y)
std(df.y)

# Linear model
using GLM
model = lm(@formula(y ~ x), df)

Executed Julia Code (requires Julia + IJulia)

In your post YAML:

---
title: "Julia Analysis"
jupyter: julia-1.9
---

Then in your post:

```julia
using Statistics
data = [1, 2, 3, 4, 5]
println("Mean: ", mean(data))
println("Std: ", std(data))
```

Pseudocode

Quarto supports several pseudocode formats:

Method 1: Using Plain Text with Custom Class

```{.pseudocode}
ALGORITHM: Linear Regression
INPUT: X (n × p matrix), y (n × 1 vector)
OUTPUT: β (p × 1 coefficient vector)

1. Initialize β = 0
2. REPEAT until convergence:
   a. Calculate residuals: r = y - Xβ
   b. Calculate gradient: g = X'r
   c. Update: β = β + α*g
3. RETURN β
```

Method 2: Using Algorithm Style

Algorithm 1: Bootstrap Confidence Interval
Input: data X, statistic θ̂, confidence level α
Output: CI = [θ_lower, θ_upper]

1: for i = 1 to B do
2:    X* ← resample(X)
3:    θ*_i ← compute_statistic(X*)
4: end for
5: θ_lower ← quantile(θ*, α/2)
6: θ_upper ← quantile(θ*, 1-α/2)
7: return [θ_lower, θ_upper]

Method 3: LaTeX-Style Algorithm (using algorithmic package)

For posts that need formal algorithmic notation, add to YAML:

---
title: "My Algorithm Post"
format:
  html:
    include-in-header:
      text: |
        <style>
        .algorithm {
          font-family: "Courier New", monospace;
          background: #f5f5f5;
          padding: 1em;
          border-left: 3px solid #007bff;
        }
        </style>
---

Then use:

::: {.algorithm}
**Algorithm 1** Maximum Likelihood Estimation

**Input:** Data $X = \{x_1, ..., x_n\}$, likelihood function $L(\theta|X)$

**Output:** $\hat{\theta}_{MLE}$

1. Initialize $\theta_0$
2. **while** not converged **do**
   - Compute $\nabla_\theta \log L(\theta|X)$
   - Update $\theta_{t+1} = \theta_t + \alpha \nabla_\theta \log L(\theta|X)$
   - Check convergence criterion
3. **end while**
4. **return** $\hat{\theta}_{MLE}$
:::

Language-Specific Settings in Post YAML

For Stata Posts

---
title: "Stata Analysis"
format:
  html:
    code-fold: false
engine: knitr
knitr:
  opts_chunk:
    engine: stata
    engine.path: "/Applications/Stata/StataSE.app/Contents/MacOS/stata-se"
---

For Julia Posts

---
title: "Julia Analysis"
format:
  html:
    code-fold: false
jupyter: julia-1.9
execute:
  cache: true
  freeze: auto
---

For Mixed Language Posts

---
title: "Multi-Language Analysis"
format:
  html:
    code-fold: false
engine: jupyter
kernels:
  - python3
  - julia-1.9
  - ir  # R kernel for Jupyter
---

Syntax Highlighting Themes

Your site uses: - Light mode: Pygments - Dark mode: Monokai

Available themes include: - pygments, tango, espresso, zenburn, kate, monochrome - haddock, breezedark, atom-one, github, monokai

To change for a specific post:

---
highlight-style:
  light: github
  dark: atom-one
---

Complete Example Post

Here’s a complete example using multiple languages:

---
title: "Comparing Statistical Methods Across Languages"
author: "Zad Rafi"
date: "2026-01-06"
categories: [statistics, programming]
format:
  html:
    code-fold: false
    code-tools: true
execute:
  warning: false
  message: false
---

## R Analysis


::: {.cell}

```{.r .cell-code}
# Linear regression in R
data <- data.frame(
  x = 1:10,
  y = 2*1:10 + rnorm(10)
)
model <- lm(y ~ x, data)
summary(model)
```
:::


## Julia Analysis

```julia
# Same analysis in Julia
using GLM, DataFrames
data = DataFrame(x = 1:10, y = 2*(1:10) .+ randn(10))
model = lm(@formula(y ~ x), data)
```

## Stata Analysis

```stata
* Same analysis in Stata
clear
set obs 10
gen x = _n
gen y = 2*x + rnormal()
regress y x
```

## Algorithm Pseudocode

```{.pseudocode}
ALGORITHM: Ordinary Least Squares
INPUT: X, y
OUTPUT: β̂

1. Compute X'X
2. Compute (X'X)^(-1)
3. Compute X'y
4. β̂ = (X'X)^(-1) X'y
5. RETURN β̂
```

Installation Requirements

For Julia Execution

# Install Julia
# Install IJulia kernel
julia -e 'using Pkg; Pkg.add("IJulia")'

For Stata Execution

# Install RStata package
install.packages("RStata")

# Configure in your R setup chunk
library(RStata)
options("RStata.StataPath" = "/Applications/StataNow/StataMP.app/Contents/MacOS/StataMP")
options("RStata.StataVersion" = 19.5)

Testing Your Setup

  1. Create a test post with code blocks
  2. Run: quarto render your-post.qmd
  3. Check the HTML output for proper syntax highlighting
  4. If executing code, verify the output appears

Troubleshooting

Stata not executing: - Check Stata path in options - Ensure RStata package is installed - Verify Stata license is active

Julia not found: - Install IJulia: julia -e 'using Pkg; Pkg.add("IJulia")' - Specify correct Julia version in YAML

Pseudocode not formatting: - Use custom CSS styling (see example above) - Or use plain text/code blocks with descriptive language name

More Information

Citation

BibTeX citation:
@online{panda,
  author = {Panda, Sir},
  title = {Code {Languages} {Guide} for {Less} {Likely}},
  url = {https://lesslikely.com/CODE_LANGUAGES_GUIDE.html},
  langid = {en}
}
For attribution, please cite this work as:
1. Panda S. ‘Code Languages Guide for Less Likely’. https://lesslikely.com/CODE_LANGUAGES_GUIDE.html.