Replicating a useful Stata Workflow with DataFramesMeta

How about this? This parallels the stata code closely.


variables_to_cap = [:price, :mpg, :headroom, :trunk, :weight]

for variable in variables_to_cap
    newvar = Symbol(string(variable,"_std"))
    q = quantile(df[variable],.99)
    df[newvar] = [!isna(x) && x > q ? q : x for x in df[variable]]
end

2 Likes