Skip to content

Commit

Permalink
finished session3
Browse files Browse the repository at this point in the history
  • Loading branch information
luisesanmartin committed Sep 21, 2023
1 parent 99d2941 commit 2cd4a94
Show file tree
Hide file tree
Showing 18 changed files with 1,248 additions and 240 deletions.
330 changes: 217 additions & 113 deletions Presentations-GeorgiaRS/202309/3-descriptive-statistics.Rmd

Large diffs are not rendered by default.

709 changes: 582 additions & 127 deletions Presentations-GeorgiaRS/202309/3-descriptive-statistics.html

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Presentations-GeorgiaRS/202309/exercises-session2.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Data
small_business_2019 <- read.csv("data/small_business_2019.csv")
small_business_2019_age <- read.csv("data/small_business_2019_age.csv")

# Exercise 3
library(dplyr)

Expand Down
40 changes: 40 additions & 0 deletions Presentations-GeorgiaRS/202309/exercises-session3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Data
small_business_2019_all <- read.csv("data/small_business_2019_all.csv")
View(small_business_2019_all)

# Exercise 1
#install.packages("modelsummary")
#install.packages("huxtable")

# Exercise 2
df_tbilisi_50 <- filter(small_business_2019,
region == "Tbilisi") %>%
arrange(-income) %>%
filter(row_number() <= 50)

# Exercise 3
library(modelsummary)
datasummary_skim(small_business_2019_all)

# Exercise 4
datasummary(
age + income + vat_liability ~ N + Mean + SD + Min + Max,
small_business_2019_all
)

# Exercise 5
library(huxtable)
stats_table <- datasummary_skim(small_business_2019_all, output = "huxtable")
quick_xlsx(stats_table, file = "quick_stats.xlsx")

# Exercise 6
stats_table_custom <- stats_table %>%
set_header_rows(1, TRUE) %>%
set_header_cols(1, TRUE) %>%
set_number_format(everywhere, 2:ncol(.), "%9.0f") %>%
set_align(1, everywhere, "center") %>%
theme_basic()
quick_xlsx(
stats_table_custom,
file = "stats-custom.xlsx"
)
125 changes: 125 additions & 0 deletions Presentations-GeorgiaRS/202309/exercises-session4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Data
small_business_2019_all <- read.csv("data/small_business_2019_all.csv")

# Exercise 1a
library(ggplot2)
ggplot(small_business_2019_all) +
aes(x = taxperiod,
y = vat_liability) +
geom_col() +
labs(title = "Total VAT liability of small businesses in 2019 by month")

# Exercise 1b
ggplot(small_business_2019_all) +
aes(x = taxperiod,
y = vat_liability) +
geom_col() +
labs(title = "Total VAT liability of small businesses in 2019 by month",
# x-axis title
x = "Month",
# y-axis title
y = "Georgian Lari") +
# telling R not to break the x-axis
scale_x_continuous(breaks = 201901:201912) +
# centering plot title
theme(plot.title = element_text(hjust = 0.5))

# Exercise 1c
ggsave("vat_liability_small_2019.png",
width = 20,
height = 10,
units = "cm")

# Exercise 2a
df_group_month <- small_business_2019_all %>%
select(group, taxperiod, vat_liability) %>%
group_by(group, taxperiod) %>%
summarize(total = sum(vat_liability))

# Exercise 2b
ggplot(df_group_month) +
aes(x = taxperiod,
y = total) +
geom_line(aes(color = group)) +
labs(title = "Total VAT liability of small businesses in 2019 by experiment group",
x = "Month",
y = "Georgian Lari") +
scale_x_continuous(breaks = 201901:201912) +
theme(plot.title = element_text(hjust = 0.5))

# Exercise 2c
ggplot(df_group_month) +
aes(x = taxperiod,
y = total) +
geom_line(aes(color = group)) +
labs(title = "Total VAT liability of small businesses in 2019 by experiment group",
x = "Month",
y = "Georgian Lari") +
scale_x_continuous(breaks = 201901:201912) +
theme(legend.text = element_text(size = 7),
axis.text.x = element_text(size = 6))

# Exercise 2d
ggsave("vat_liability_small_2019_by_group.png",
width = 20,
height = 10,
units = "cm")

# Exercise 3a
df_month <- small_business_2019_all %>%
select(taxperiod, vat_liability) %>%
group_by(taxperiod) %>%
summarize(total = sum(vat_liability))

# Exercise 3b
ggplot(df_month) +
aes(x = taxperiod,
y = total) +
geom_col() +
geom_text(aes(label = total),
position = position_dodge(width = 1),
vjust = -0.5,
size = 3) +
labs(title = "Total VAT liability of small businesses in 2019 by month",
x = "Month",
y = "Georgian Lari") +
scale_x_continuous(breaks = 201901:201912) +
theme(plot.title = element_text(hjust = 0.5))

# Exercise 3c
ggplot(df_month) +
aes(x = taxperiod,
y = total) +
geom_col() +
geom_text(aes(label = round(total)),
position = position_dodge(width = 1),
vjust = -0.5,
size = 3) +
labs(title = "Total VAT liability of small businesses in 2019 by month",
x = "Month",
y = "Georgian Lari") +
scale_x_continuous(breaks = 201901:201912) +
theme(plot.title = element_text(hjust = 0.5))

# Saving
ggsave("vat_liability_small_2019_text.png",
width = 20,
height = 10,
units = "cm")

# Exercise 4
ggplot(small_business_2019_all) +
aes(x = age,
y = vat_liability) +
geom_point() +
labs(title = "VAT liability versus age for small businesses in 2019",
x = "Age of firm (years)",
y = "VAT liability") +
theme(plot.title = element_text(hjust = 0.5))

# Saving
ggsave("scatter_age_vat.png",
width = 20,
height = 10,
units = "cm")

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions Presentations-GeorgiaRS/202309/libs/kePrint/kePrint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$(document).ready(function(){
if (typeof $('[data-toggle="tooltip"]').tooltip === 'function') {
$('[data-toggle="tooltip"]').tooltip();
}
if ($('[data-toggle="popover"]').popover === 'function') {
$('[data-toggle="popover"]').popover();
}
});
Loading

0 comments on commit 2cd4a94

Please sign in to comment.