My Julia DataFrames cheatsheet

Creating and calculating within groups

In Stata:

bysort group1 group2 (t): egen sum = sum(freq)

generate prob = freq/sum

bysort group1 group2: gen cumul = sum(prob)

In Julia:

sort!(df, [:group1, :group2, :t])

df = transform(groupby(df, [:group1, :group2]), :freq => sum => :sum)

df[:, :prob] = df[:, :freq]./df[:, :sum]

df = transform(groupby(df, [:group1, :group2]), :prob => cumsum => :cumul)

Collapsing data

Stata: collapse (sum) freq, by(group)

Julia: combine(groupby(df, group), :freq => sum => :freq)

Leave a Reply

Your email address will not be published. Required fields are marked *