using DataFrames, FixedEffectModels
N = 10000000
K = 100
id1 = rand(1:(N/K), N)
id2 = rand(1:K, N)
x1 =  randn(N)
x2 =  randn(N)
w = cos(id1)
y= 3 .* x1 .+ 5 .* x2 .+ cos(id1) .+ cos(id2).^2 .+ randn(N)
df = DataFrame(id1 = pool(id1), id2 = pool(id2), x1 = x1, x2 = x2, w = w, y = y)
@time reg(y ~ x1 + x2, df)
# 1.258554 seconds (723 allocations: 1.205 GB, 18.70% gc time)
#852MB to obtain the matrix etc, and then 1.205 for Regressions part
@time reg(y ~ x1 + x2, df, VcovCluster(:id2))
#  1.569679 seconds (843 allocations: 1.293 GB, 25.21% gc time)
@time reg(y ~ x1 + x2 |> id1, df)
# 1.476390 seconds (890 allocations: 1.175 GB, 20.15% gc time)
@time reg(y ~ x1 + x2 |> id1, df, VcovCluster(:id1))
# 1.974738 seconds (1.04 k allocations: 1.255 GB, 15.85% gc time)
@time reg(y ~ x1 + x2 |> id1 + id2, df)
# 4.554836 seconds (1.01 k allocations: 1.188 GB, 9.56% gc time)
@time reg(y ~ x1 + x2 |> id1, df, weight = :w)
# 2.000850 seconds (20.00 M allocations: 1.010 GB, 18.82% gc time)
@time reg(y ~ x1 + x2 |> id1 + id2, df, weight = :w)
# 4.118974 seconds (20.00 M allocations: 1.018 GB, 9.60% gc time)