Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created February 14, 2014 16:04
Show Gist options
  • Save cigrainger/9003687 to your computer and use it in GitHub Desktop.
Save cigrainger/9003687 to your computer and use it in GitHub Desktop.
library(foreign)
library(dplyr)
library(zoo)
df1 <- read.dta('~/AeroFS/Googlestuff/searchtechnology-collapsed.dta')
df2 <- read.dta('~/AeroFS/Googlestuff/mergedquarterly.dta')
load('googledates.rdata')
df1 <- left_join(df1,monthlookup,by='time')
df1$time <- NULL
names(df1)[names(df1)=='month'] <- 'time'
df1$time <- as.Date(df1$time)
df1$year <- substr(df1$time,1,4)
df1$month <- substr(df1$time,6,7)
df1$quarter[df1$month <= 3] <- 1
df1$quarter[df1$month > 3 & df1$month <= 6] <- 2
df1$quarter[df1$month > 6 & df1$month <= 9] <- 3
df1$quarter[df1$month > 9 & df1$month <= 12] <- 4
df1 <- df1[,c('country','technology','searchintensity','year','quarter')]
df1 <- summarise(group_by(df1,country,technology,year,quarter), mean(searchintensity))
names(df1)[names(df1)=='mean(searchintensity)'] <- 'searchintensity'
df1$year <- as.numeric(df1$year)
df2$year <- as.numeric(df2$year)
df2$quarter <- as.numeric(df2$quarter)
df <- left_join(df2,df1,by=c('country','technology','year','quarter'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment