Skip to content

Instantly share code, notes, and snippets.

@cigrainger
cigrainger / BE_1.py
Created February 16, 2015 15:05
meanvar
import numpy as np
from numpy import random
m = 1000
tot_n = np.zeros(m)
for i in list(range(m)):
n = 1
mcint = random.randn(n)
mean = str(np.mean(mcint)).split('.')
while mean[1][:3] != '000':
@cigrainger
cigrainger / BE_1.py
Created February 16, 2015 15:03
mcint
import numpy as np
from numpy import random
m = 1000
tot_n = np.zeros(m)
for i in list(range(m)):
n = 1
mcint = random.randn(n)
mean = str(np.mean(mcint)).split('.')
while mean[1][:3] != '000':
import pandas as pd
import re, string
import numpy as np
from scipy.spatial.distance import pdist, squareform, euclidean
def firmmeans(data,year,key):
d = data[data['bvdid'].isin(key['bvdid'][key['year']==year].tolist())]
d[['year']] = d[['year']].astype(int)
d = d[d['year']<=year]
cols = [col for col in d.columns.values if col not in ['year','appln_id']]
library(xlsx)
library(reshape2)
library(dplyr)
options(xlsx.datetime.format="yyyy-mm-dd")
df <- read.xlsx('SPLICE results full - xlsx.xlsx',sheetIndex=2,header=TRUE,stringsAsFactors=FALSE,startRow=3)
df <- df[-72,]
id <- df[,1:4]
sheet1 <- select(df,ends_with('Potential.Contribution.of.Energy.System.Components'))
sheet2 <- select(df,ends_with('Criticality.of.Energy.System.Components'))
sheet3 <- select(df,ends_with('Persistence.of.Impacts'))
install.packages('stargazer')
states <- state.name
# states <- c(states,states)
states <- rep(times=2,x=states)
variable <- c(rep('x',50),rep('y',50))
# Create a dataframe called df consisting of states and variable.
df <- data.frame(states,variable)
install.packages('stargazer')
# states <- state.name
states <- rep(state.name,2)
# states <- rep(2,state.name)
# states1 <- rep(x=state.name,times=2)
# states2 <- rep(times=2,x=state.name)
# states1==states2
variable <- c(rep('x',50),rep('y',50))
import pandas as pd
import pystan
df = pd.read_csv('firms.csv')
df = df.dropna()
country = pd.Categorical(df.country)
year = pd.Categorical(df.year)
nace = pd.Categorical(df.nace)
bvd_id = pd.Categorical(df.bvd_id)
for firm in pd.unique(firms.bvdid):
firms.ix[((firms.bvdid==firm)&(firms.year==2004)),'stock'] = firms.stock[(firms.bvdid==firm)&(firms.year==2004)] + firms.patents[(firms.bvdid==firm)&(firms.year==2004)]
for i in range(2005,2014):
firms.ix[((firms.bvdid==firm)&(firms.year==i)),'stock'] = firms.stock[(firms.bvdid==firm)&(firms.year==i-1)] + firms.patents[(firms.bvdid==firm)&(firms.year==i)]
COPY (SELECT abstracts FROM patents
WHERE lang = 'en'
ORDER BY random()
LIMIT 10000000)
TO E'~/randomsample.txt';
turnover.columns = [x[-4:] if x.startswith('turnover')
else x
for x in turnover.columns.values]
turnover = pd.melt(turnover,id_vars=['bvd_id'],var_name='year',value_name='turnover')
turnover.year = turnover.year.astype('int')
turnover.turnover = [np.nan if x == 'n.a.'
else x
for x in turnover.turnover]
turnover.turnover = [str(x).replace(',','') if x != np.nan
else x