Virata manual

contract

Replaces the data with one row per combination, and a count.

What we have

  • one row per combination, with a _freq count
  • percent()

Coming later

Nothing known to be missing.

How you write it

contract varlist

Square brackets mean optional. A vertical bar means choose one.

What it does

The simplest possible collapse: how many rows had each combination of these columns. contract state sector gives you one row per state-and-sector with a frequency column _freq.

The same numbers tabulate would print, but as a dataset — so you can sort them, chart them or save them.

Try it

Every example below was run after sysuse vira.sample02, clear.

. contract state sector
The same thing in pandas and in R

pandas

df = df.groupby(['state', 'sector']).size().reset_index(name="_freq")

R

library(dplyr)
df <- df %>% count(state, sector, name = "_freq")

# This R was run in a real R (4.6.1) and gave the same numbers.

Nearby

merge append joinby cross collapse reshape