Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for ids to be defined with multiple variables #29

Open
eloualiche opened this issue Jan 23, 2024 · 2 comments
Open

Allow for ids to be defined with multiple variables #29

eloualiche opened this issue Jan 23, 2024 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@eloualiche
Copy link

eloualiche commented Jan 23, 2024

More of a wish than a necessity.
Sometimes my id is composed of two variables to uniquely identify one observation for one date.

One such example would be in finance stockholding dataset: individual i holds N shares of stock j at time t.
How many were they holding at time t-1?

ideally

lag!(df, [:stock_id, :investor_id], :date, :portfolio_holding)

Since my understanding is that this package uses PanelShift.jl, this could be built in.
Their version of a shift is (their readme)

function panellag!(df, id, t, x, newx, n=oneunit(df[1, t] - df[1, t]); checksorted=true)
    return transform!(groupby(df, id), [t, x] => ((t, x) -> tlag(t, x, n; checksorted=checksorted)) => newx)
end

So the groupby argument can be either one or an array of ids.

Thank you!

@eirikbrandsaas
Copy link
Owner

Thank you for the suggestion, yes that should be easy to add in. For now, as I bet you know, you could just create the new panel ID first, so it is unique based on the two variables you have, and then use the package as is.

That said, I really need to revisit this package. It is very slow for even moderate sizes and doesn't work for all time formats. I was really hoping that by now somebody had written a better package, but I think PanelShift.jl is still the closest, and this really is just a convenience wrapper around that package.

@eirikbrandsaas eirikbrandsaas added this to the v1.0 milestone Jan 24, 2024
@eloualiche
Copy link
Author

Thank you for the update.
The package is good. As long as it is fairly stable, I have not had major issues with it. To be honest I do switch back and forth with PanelShift depending on what I need (and what I remember).

Thanks for the great work!

@eirikbrandsaas eirikbrandsaas added the enhancement New feature or request label Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants