Skip to content

Instantly share code, notes, and snippets.

View christophsax's full-sized avatar

Christoph Sax christophsax

View GitHub Profile
We can make this file beautiful and searchable if this error is corrected: It looks like row 5 should actually have 19 columns, instead of 2. in line 4.
id,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025
Einnahmen,64626987042060,70879681716000,64283526391450,66805566752980,65001776209490,67749345457040,65413356862180,68383475359200,71059585910600,73414202114620,76115434968500,76953145837330,73429902178500,76664986400000,79717180500000,81804672200000,83027897400000,84659430600000
Einnahmen > Ertrag,64375327966740,65205100668200,63950881889520,65921999311200,64779337153410,66216599079490,65072728118170,68017644513290,70183445361950,72687751733340,74845228658230,76201274068400,72723482580310,75988717300000,78993402500000,81063777900000,82232655900000,83858480500000
Einnahmen > Ertrag > Fiskalertrag,58052128664830,56789874552120,57756523349950,60096024353080,58288097285280,60337880047620,60188442169370,62689212719070,63098518215700,66196789451970,68597756927080,69891809439560,67236991404630,71066062200000,73092762500000,75220748200000,76518928800000,78133148300000
Einnahmen > Ertrag > Fiskalertrag > Direkte Bundessteuer,1
@christophsax
christophsax / warnings.md
Created November 19, 2021 17:54
Collecting warnings in a data frame

Function with multiple warnings

fun_w_multiple_warnings <- function() {
  log(-1)
  log(-1)
  warning("one more")
  TRUE
}
fun_w_multiple_warnings()
library(seasonal)
# basic use
m <- seas(AirPassengers)
summary(m)
# understanding the defaults
?seas
# some methods

trendecon: daily economic indicators based on Google searches

Project

During the Covid-19 pandemic, information about the economic and social situation has changed rapidly. Traditional indicators are not sufficiently frequent to monitor and forecast economic and social activity at high frequency. We use Google search trends to overcome this data gap and create meaningful indicators. We extract daily search data on keywords reflecting consumers' perception of the economic situation. The indicators are available at www.trendecon.org.

An accompanying R package contains the code to construct long daily time series from Google Trends for any keyword. Robustness of the series is achieved by querying Google multiple times. The queries are sampled at daily, weekly and monthly frequencies and then harmonized such that the long term trend is preserved. A more detailed methodological description is given on the website. We are currently summarizin

@christophsax
christophsax / covid-19-ita.md
Last active April 27, 2020 20:27
Covid-19 Italy and Italian Provinces
library(tidyverse)

# download all province data from
# https://github.com/pcm-dpc/COVID-19/tree/master/dati-province
url <- "https://raw.githubusercontent.com/pcm-dpc/COVID-19/master/dati-province/dpc-covid19-ita-province.csv"
dta <- read_csv(url, col_types = cols()) %>%
  transmute(time = data, region = denominazione_regione, province = denominazione_provincia, value = totale_casi)

dta <-
@christophsax
christophsax / covid-19.md
Last active April 5, 2020 20:17
Coronavirus disease: new infections and total cases
library(tidyverse)
library(anytime)

# Data Repo Johns Hopkins CSSE
# https://github.com/CSSEGISandData/COVID-19
url <- "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_time_series/time_series_covid19_confirmed_global.csv"
dta_raw <- read_csv(url, col_types = cols()) %>%
  select(-Lat, -Long)
@christophsax
christophsax / demo.md
Created May 31, 2018 20:15
gross debt of swiss cantons
library(tidyverse)
library(readxl)
library(geofacet)

url <- "http://www.data.efv.admin.ch/Finanzstatistik/d/fs_ktn/ktn_schuld.xlsx"
tf <- tempfile(fileext = ".xlsx")
download.file(url, tf)
dta <- read_excel(tf, sheet = "schuld_per_capita", skip = 6) %>% 
 select(-X__1) %&gt;% 
@christophsax
christophsax / download.md
Last active May 21, 2018 14:14
Reading data from Gapminder repo into R

It's relatively straigtforward to read the Gapminder data directly from the Systema Globalis repo into R. Here's the code to produce an extract with the Gapminder core variables.

The result is stored below and can be accessed by:

gapminder <- read.csv("https://gist.githubusercontent.com/christophsax/8d2814a7d3e464d020e38a9cb468930b/raw/361889b5ea7830e2bf8f28f40239a2a08765432d/gapminder.csv", stringsAsFactors = FALSE)

library(ggplot2)
@christophsax
christophsax / demo.md
Created May 17, 2018 17:20
Multivariate Time Series from Quantmod
library(tsbox)
suppressMessages(library(quantmod))
suppressMessages(library(ggplot2))

ts_fred <- function(..., class = "data.frame") {
  symb <- c(...)
  dta.env <- new.env()
  suppressMessages(getSymbols(symb, env = dta.env, src = "FRED"))
 z &lt;- data.table::rbindlist(lapply(as.list(dta.env), ts_dt), idcol = "id")
@christophsax
christophsax / swiss.csv
Created May 12, 2018 18:57
R dataset swiss
Location Fertility Agriculture Examination Education Catholic Infant.Mortality
Courtelary 80.2 17 15 12 9.96 22.2
Delemont 83.1 45.1 6 9 84.84 22.2
Franches-Mnt 92.5 39.7 5 5 93.4 20.2
Moutier 85.8 36.5 12 7 33.77 20.3
Neuveville 76.9 43.5 17 15 5.16 20.6
Porrentruy 76.1 35.3 9 7 90.57 26.6
Broye 83.8 70.2 16 7 92.85 23.6
Glane 92.4 67.8 14 8 97.16 24.9
Gruyere 82.4 53.3 12 7 97.67 21