Publications by Tony Cookson
Dates in R and the First Day of the Month
I spent some time this morning learning about how R thinks about dates in R. I found this website to be a useful guide.Imagine that your data are dates in a standard format [YEAR-MONTH-DAY (as in 2011-23-04) is one such format] and you want a vector of the dates that are the first day in the month of your data set. You might, for ex...
1162 sym 2 img
Merging Multiple Data Files into One Data Frame
We often encounter situations where we have data in multiple files, at different frequencies and on different subsets of observations, but we would like to match them to one another as completely and systematically as possible. In R, the merge() command is a great way to match two data frames together.Just read the two data frames in...
3276 sym 2 img
Merging Data Video Tutorial
Here’s a video tutorial where I walk through some code that does what the previous post describes.The FRED data is used extensively for macroeconomics. You might these data useful for joining in graph fights in the blogosphere. Related To leave a comment for the author, please follow the link and comment on their blog: Coffee an...
661 sym 2 img
R Bloggers
I recently found a great resource for R in the blogosphere, the R Bloggers Blog Aggregator. Basically, the site aggregates posts from a bunch of blogs about R (like this one!) into a giant feed of uses for R. If you are interested in learning more about R, the best way is to see how other people interact with it. What better way th...
813 sym 2 img
Automatically Save Your Plots to a Folder
Suppose you’re working on a problem that involves a loop for calculations. At each iteration inside the loop, you want to construct a plot. Not only do you want to see the plot, but you would like to save each plot for a presentation, report or paper. Furthermore, the loop goes on for a while (say through the 26-letters of the al...
4335 sym 2 img
Forming Formulas
One of the first functions a new R user learns how to use is the lm() command, which involves stating the model formula.lm(y~x1+x2, data=mydata)After a while, this just becomes a natural way to say “I want a regression of y on x1 and x2 using mydata.” Even though it is natural, the underlying structure of the formula is not as it first appea...
3675 sym R (1396 sym/13 pcs) 2 img
Putting Robust Standard Errors into LaTeX Tables: An Extension of mtable
I recently discovered the mtable() command in the memisc library and its use with toLatex() to produce nice summary output for lm and glm objects in a nicely formatted table like this:Once you have your linear model objects, all you need is one command — a composite of toLatex() and mtable(). Here’s the R code I used to generate ...
3774 sym 6 img
Extending mtable() to ivreg, gls and robust standard errors
I have written several extensions of the mtable() command in the memisc library that may come in handy. The methods are available in a package I have written called tonymisc (now, available on CRAN). A zipped folder with my package files is available for download here.My extensions to mtable() allow users to easily summarize (and po...
2059 sym 6 img
Describing Data: Frequently Used Commands
Obtaining a coherent numerical summary of data is a common task, and it is common to want to port these summary statistics into a table of results. When I am in interactive mode with my data, I use the summary() command applied to my data frame. For example, the following code loads and summarizes a data frame on Yogurt advertising ...
2761 sym 2 img
Porting Stata-like Marginal Effects to LaTeX
The TimeSeriesIreland Blog posted an excellent start on a function that automatically computes marginal effects for probit and logit models. As I have always wanted an easy-to-use function that computes and reports marginal effects in R, I was elated to see the function and I couldn’t wait to use it.My initial impression when I saw...
4019 sym 6 img