psData
psData copied to clipboard
S4 development branch
Hi,
Here's a draft S4 class that creates a subclass of data.frame to implement functions for panel data and time series manipulation, or for any dyadic data.
Contents
CountryIDby @christophergandrud (wraps aroundcountrycodeby @vincentarelbundock, with edits)MoveFrontfromDataCombineby @christophergandrudclass-HomogListandsubclass_homog_listfromDataFrameConstrby @jrnoldclass-psData(hacked fromDataFrameConstrby @jrnold)constrained_data_framefromDataFrameConstrby @jrnolddebt.rda(demo Reinhart and Rogoff data)get_dataand a bunch of get (download) functions for e.g. Polity 4 and QOG datapanelwith functions by @zmjonesutils(with snippets by more authors)
I'm sure many more people have written useful code for working with panel data, including for visualization purposes—the package should probably also look in that direction, and the draft includes a Reinhart and Rogoff plot.
Output
# install
devtools::install_github("briatte/psData")
library(psData)
# example
data(debt)
The object is of class data.frame:
> head(debt)
Country Year growth ratio
1 Australia 1946 -3.557951 190.41908
2 Australia 1947 2.459475 177.32137
3 Australia 1948 6.437534 148.92981
4 Australia 1949 6.611994 125.82870
5 Australia 1950 6.920201 109.80940
6 Australia 1951 4.272612 87.09448
Now add panel design variables to quickly create a psData panel object:
> as.panel(debt, "Country", "Year")
Panel data frame [ 1171 rows x 4 columns, 20 Country x 64 Year ]
Country Year growth ratio
1 Australia 1946 -3.557951 190.41908
2 Australia 1947 2.459475 177.32137
3 Australia 1948 6.437534 148.92981
4 Australia 1949 6.611994 125.82870
5 Australia 1950 6.920201 109.80940
6 Australia 1951 4.272612 87.09448
The object is now a data.frame to which the package can pass functions similar to the xt and ts commands in Stata. Country codes and basic date formats are automatically detected and usable for safe merges between multiple panel data.
Excellent work. Sorry I've been a bit remiss lately because of other projects.
However, I just added the work you did into a new branch to the main rOpenGov/psData repo. It's called devPanel.
If it's ok with you, I think we should focus development around this branch.
Your listed as collaborator on the repo so you should be able to push and pull freely. Let me know if you have any issues.
One more thing. I added the email address listed on your website to the .travis.yml. So you'll get updates of whether or not each commit passes. Let me know if you don't want this and we could just take it out.
@christophergandrud I'm good with all suggestions, will continue development at end of March (writing up before that).
Thanks. I'll have to take a closer look at this when I have some time. I'm curious about the ropengov project.
Sorry that I didn't notice that you were using dataframeconstr earlier. You should look at my package checker. It is the continuation of the package; though I'd have to remind myself of what I changed and updated in the code.
Jeff
I'm good with all suggestions, will continue development at end of March (writing up before that).
Reply to this email directly or view it on GitHub.
@jrnold don't worry about timing, I forked your repo just a few days ago :)
It's likely that my hack of your class can be improved in many ways. Please feel free to point inadequacies, there are many, as I am new to S4 classes overall.
Thanks. Again sorry for my delay. What I was saying is that you should look at my package https://github.com/jrnold/r-checker. It is an updated version of dataframeconstr; I should have probably removed this package. I'd need to look back over my code to remind myself what changed, but I must have improved some things.
Jeff
@jrnold https://github.com/jrnold don't worry about timing, I forked your repo just a few days ago :)
It's likely that my hack of your class can be improved in many ways. Please feel free to point inadequacies, there are many, as I am new to S4 classes overall.
Reply to this email directly or view it on GitHubhttps://github.com/rOpenGov/psData/issues/7#issuecomment-37060114 .
@jrnold thanks for the details — I'll update psData to that version of your S4 class next week.