This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(RSQLite) | |
require(mitools) | |
require(stringr) | |
require(plyr) | |
#Import data and create panel data set | |
for(i in 2007:2011){ | |
setwd("~/Documents/CEX0711") | |
year <- i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prices <- read.csv("~/Documents/CEX0711/prices.csv") | |
colnames(prices) <- sub("[.]", " ", colnames(prices)) | |
prices <- melt(prices) | |
prices$Date <- as.yearmon(prices$Date,format="%b-%Y") | |
colnames(prices) <- c('time','statename','price') | |
prices$year <- format(prices$time,format="%Y") | |
statetax <- read.csv("~/Documents/CEX0711/statetax.csv") | |
colnames(statetax)[1] <- "statename" | |
colnames(statetax) <- sub("[X]", "", colnames(statetax)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Impute price data | |
prices <- read.csv("~/Documents/CEX0711/prices.csv") | |
colnames(prices) <- sub("[.]", " ", colnames(prices)) | |
prices <- melt(prices) | |
prices$Date <- as.yearmon(prices$Date,format="%b-%Y") | |
colnames(prices) <- c('time','statename','price') | |
prices$year <- format(prices$time,format="%Y") | |
statetax <- read.csv("~/Documents/CEX0711/statetax.csv") | |
colnames(statetax)[1] <- "statename" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prep.wdi <- function(x,cache=FALSE,filename=paste(Sys.time()),country='name',format='wide'){ | |
require(reshape2) | |
if (!is.character(x)) {stop('x must be a string.')} | |
df <- read.csv(x) | |
if (names(df)[1] != 'Country.Name' | | |
names(df)[2] != 'Country.Code' | | |
names(df)[3] != 'Indicator.Name' | | |
names(df)[4] != 'Indicator.Code') { | |
stop('This is not a properly formatted WDI csv.') | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quarterCalc <- function(interviewTime, interviewState, priceData){ | |
if(!inherits(interviewTime, "yearmon")){ | |
stop("Wrong date type") | |
} | |
newData <- subset(priceData, as.character(priceData$statename)==as.character(interviewState)) | |
if(dim(subset(priceData, time==interviewTime & as.character(statename)==as.character(interviewState)))[1] > 1){return(NA)} | |
index = which(newData$time == interviewTime, arr.ind=TRUE) | |
if(length(index)>1){ stop(print(index))} | |
else if(index>=3){ | |
quarterly <- data.frame("time" = interviewTime, "state" = interviewState, "price" = mean(newData$nprc[seq((index-3), (index-1), 1)], na.rm=TRUE)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
students = pd.read_csv('students.csv') | |
def newstudent(x): | |
newname = raw_input("What is the student's name? ") | |
newemail = raw_input("What is the student's email address? ") | |
newrow = [{'name':newname,'email':newemail}] | |
df = x.append(newrow, ignore_index=True) | |
return df | |
def addstudent(x): | |
newdf = newstudent(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
f = open('students.csv').read() | |
while f.split('\n')[0] != 'name,email': | |
morecsv = raw_input("This does not look like the correct file. Would you like to see more? y/n?") | |
while morecsv != 'y' or 'n': | |
morecsv = raw_input("The prompt was y/n only. Would you like to see more? y/n?") | |
if morecsv == 'y': | |
print f.split('\n')[:10] | |
newcsv = raw_input("Would you like to overwrite this file to create the student list? y/n?") | |
while newcsv != 'y' or 'n': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
f = open('students.csv').read() | |
while f.split('\n')[0] != 'name,email': | |
morecsv = raw_input("This does not look like the correct file. Would you like to see more? y/n?") | |
while morecsv != 'y' or 'n': | |
morecsv = raw_input("The prompt was y/n only. Would you like to see more? y/n?") | |
if morecsv == 'y': | |
print f.split('\n')[:10] | |
newcsv = raw_input("Would you like to overwrite this file to create the student list? y/n?") | |
while newcsv != 'y' or 'n': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
f = open('students.csv').read() | |
while f.split('\n')[0] != 'name,email': | |
morecsv = raw_input("This does not look like the correct file. Would you like to see more? y/n?") | |
while morecsv != 'y' and 'n': | |
morecsv = raw_input("The prompt was y/n only. Would you like to see more? y/n?") | |
if morecsv == 'y': | |
print f.split('\n')[:10] | |
newcsv = raw_input("Would you like to overwrite this file to create the student list? y/n?") | |
while newcsv != 'y' and 'n': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
f = open('students.csv').read() | |
while f.split('\n')[0] != 'name,email': | |
morecsv = raw_input("This does not look like the correct file. Would you like to see more? y/n?") | |
while morecsv != 'y' and 'n': | |
morecsv = raw_input("The prompt was y/n only. Would you like to see more? y/n?") | |
if morecsv == 'y': | |
print f.split('\n')[:10] | |
newcsv = raw_input("Would you like to overwrite this file to create the student list? y/n?") | |
while newcsv != 'y' and 'n': |
OlderNewer