Skip to content

Instantly share code, notes, and snippets.

## ------------------------- ##
## An Example of ##
## Automating Plot Output ##
## ------------------------- ##
names = LETTERS[1:26] ## Gives a sequence of the letters of the alphabet
beta1 = rnorm(26, 5, 2) ## A vector of slopes (one for each letter)
beta0 = 10 ## A common intercept
## ------------------------- ##
## An Example of ##
## Automating Plot Output ##
## ------------------------- ##
names = LETTERS[1:26] ## Gives a sequence of the letters of the alphabet
beta1 = rnorm(26, 5, 2) ## A vector of slopes (one for each letter)
beta0 = 10 ## A common intercept
## --------------------------- ##
## Function takes a vector of ##
## dates as its input. ##
## ##
## It produces a vector of ##
## dates that are the first ##
## in their respective months ##
## --------------------------- ##
firstDayMonth=function(x)
## ------------------------ ##
## Data Creation in R ##
## Tutorial by Tony Cookson ##
## ------------------------ ##
## Simplest way to create a vector is to use the colon.
a = 1:4
b = 4:1
a
b
## ----------------------- ##
## Computing and Graphing ##
## Statistical Power ##
## ----------------------- ##
## Parameters of the Problem ##
mu0 = 6 ## Null-hypothesized value
alpha = 0.05 ## Significance Level
s.sq = 16 ## Variance from pilot study
## -------------------------- ##
## An R Function that Shades ##
## under a normal density. ##
## ##
## This is a convenience ##
## function for polygon() ##
## -------------------------- ##
shadenorm = function(below=NULL, above=NULL, pcts = c(0.025,0.975), mu=0, sig=1, numpts = 500, color = "gray", dens = 40,
lines=FALSE,between=NULL,outside=NULL){
## ---------------------------------------------------------------------------------------- ##
## Author: John Fox ##
## Source: http://r.789695.n4.nabble.com/R-extend-summary-lm-for-hccm-td815004.html ##
## Adapted by Tony Cookson. ##
## -- Only Change Made: Changed the name of the function (unwisely maybe) ##
## to summaryR from summaryHCCM.lm. I also changed the spelling of consistent ##
## ---------------------------------------------------------------------------------------- ##
summaryR.lm <- function(model, type=c("hc3", "hc0", "hc1", "hc2", "hc4"), ...){
## -------------------------------------- ##
## R Tutorial on Robust Standard Errors ##
## Author: Tony Cookson ##
## -------------------------------------- ##
## Read Data
library(foreign)
ed = read.dta("C://R//edudat2.dta")
## Obtain regression object
## ----------------------------------- ##
## A homegrown IV regression command ##
## that handles the case where there ##
## is one endogenous variable and many ##
## (or one) instrument. ##
## ##
## Disadvantage: The command doesn't ##
## handle multiple endogenous vars ##
## ##
## Advantage: testing for relevance, ##
## ------------------------ ##
## An Easy IV regression ##
## regression command for R ##
## ##
## Author: Tony Cookson ##
## Commands: ivregress() ##
## sum.iv() ##
## ------------------------ ##
## Read Data ##