Skip to content

Commit

Permalink
#85: Adds primary example case + quits program after exports
Browse files Browse the repository at this point in the history
  • Loading branch information
snairdesai committed Nov 15, 2023
1 parent 9d676e8 commit e09b9f7
Show file tree
Hide file tree
Showing 48 changed files with 1,285 additions and 1,207 deletions.
52 changes: 49 additions & 3 deletions analysis/code/gen_scalars.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ library(tidyverse)
library(openxlsx)
set.seed(123)

#### Scalars for gps_primary.xlsx ####

# This is the primary example, based on Table 1 from ad-price-drivers:
# chrome-extension://efaidnbmnnnibpcajpcglclefindmkaj/https://scholar.harvard.edu/files/shapiro/files/ad-price-drivers.pdf

#### Scalars for gs_widetable.xlsx ####

# I'm just manually transcribing from the paper here, of course
# in practice we will compute these ourselves and store in variables.
# In the tables below, I compute random placeholders for the scalars.
data <- t(data.frame(

c("-1.5556", "(0.2913)", "0.0973", "(0.0292)", "0.0124", "(0.0031)", "103", "809", "", "", "", ""),
c("-0.0285", "(0.0079)", "-0.4690", "(0.2599)", "0.1221", "(0.0306)", "0.0152", "(0.0034)", "103", "809", "", ""),
c("-1.6799", "(0.0607)", "0.0082", "(0.0044)", "0.0002", "(0.0004)", "103", "809", "", "", "", ""),
c("-0.0028", "(0.0024)", "-0.3056", "(0.0933)", "0.0418", "(0.0109)", "0.0057", "(0.0016)", "103", "809", "", ""),
c("-1.8388", "(0.1027)", "0.0198", "(0.0075)", "0.0102", "(0.0008)", "103", "809", "", "", "", ""),
c("-0.0020", "(0.0029)", "-0.5230", "(0.1228)", "0.0628", "(0.0125)", "0.0152", "(0.0018)", "103", "809", "", "")

))

# Convert the matrix into a dataframe
vals_df <- as.data.frame(data, stringsAsFactors = FALSE)

# Write the data frame to a .csv and .xlsx file.
write.csv(vals_df, "output/gs_primary_scalars.csv", row.names = FALSE, sep = ";", quote = TRUE)
write.xlsx(vals_df, "output/gs_primary_scalars.xlsx", sheetName = "Placeholders", row.names = FALSE, col.names = FALSE, quote = TRUE)

# Defining placeholder matrix elements
num_columns <- 5
num_rows <- 4
Expand All @@ -23,6 +51,24 @@ combined_data[2,] <- vals_parenth[1,]
combined_data[4,] <- vals_parenth[2,]
combined_data[5:6, ] <- as.character(formatC(as.numeric(as.character(unlist(combined_data[5:6, ]))), big.mark = ",", format = "d", decimal.mark = ""))

# Write the data frame to a .txt and .xlsx file.
write.csv(combined_data, "output/gps_scalars.csv", row.names = FALSE, sep = ";", quote = TRUE)
write.xlsx(combined_data, "output/gps_scalars.xlsx", sheetName = "Placeholders", row.names = FALSE, col.names = FALSE, quote = TRUE)
# Write the data frame to a .csv and .xlsx file.
write.csv(combined_data, "output/gs_widetable_scalars.csv", row.names = FALSE, sep = ";", quote = TRUE)
write.xlsx(combined_data, "output/gs_widetable_scalars.xlsx", sheetName = "Placeholders", row.names = FALSE, col.names = FALSE, quote = TRUE)

#### Scalars for gs_widetable_extreme.xlsx ####

# I'm intentionally creating a very ugly matrix here, to demonstrate that with this new
# approach where we explicitly form links between sheets; the dimensions of this matrix
# no longer matters. We only need number of filled cells in matrix = number of required scalars in skeleton.
num_columns <- 60
num_rows <- 1

# Generate random values as placeholders.
vals <- sort(runif(num_columns * num_rows, min = 36275, max = 5245121), decreasing = TRUE)
vals <- round(vals)
formatted_vals <- formatC(vals, format = "f", big.mark = ",", digits = 0)
vals_df <- as.data.frame(matrix(formatted_vals, nrow = num_rows))

# Write the data frame to a .csv and .xlsx file.
write.csv(vals_df, "output/gs_widetable_extreme_scalars.csv", row.names = FALSE, sep = ";", quote = TRUE)
write.xlsx(vals_df, "output/gs_widetable_extreme_scalars.xlsx", sheetName = "Placeholders", row.names = FALSE, col.names = FALSE, quote = TRUE)
20 changes: 16 additions & 4 deletions analysis/log/make.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--------------------------------------------------------------------------------
Makelog started: 2023-11-14 19:09:28
Makelog started: 2023-11-15 14:49:28
Working directory: /Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis
--------------------------------------------------------------------------------
Input links successfully created!
Expand All @@ -14,7 +14,7 @@ Inputs contain missing values. Dropping rows with missing observations.
Executing command: `Rscript --no-save "/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/code/gen_scalars.R"`

The downloaded binary packages are in
/var/folders/xn/d2jgqxlj145gq5jy3hbxym0c0000gn/T//RtmpeROqmR/downloaded_packages
/var/folders/xn/d2jgqxlj145gq5jy3hbxym0c0000gn/T//Rtmpt0UcUj/downloaded_packages

trying URL 'http://cran.us.r-project.org/bin/macosx/big-sur-arm64/contrib/4.2/openxlsx_4.2.5.2.tgz'
Content type 'application/x-gzip' length 3189540 bytes (3.0 MB)
Expand All @@ -32,14 +32,26 @@ downloaded 3.0 MB
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
Warning message:
In write.csv(combined_data, "output/gps_scalars.csv", row.names = FALSE, :
In write.csv(vals_df, "output/gs_primary_scalars.csv", row.names = FALSE, :
attempt to set 'sep' ignored
Warning messages:
1: Please use 'rowNames' instead of 'row.names'
2: Please use 'colNames' instead of 'col.names'
Warning message:
In write.csv(combined_data, "output/gs_widetable_scalars.csv", row.names = FALSE, :
attempt to set 'sep' ignored
Warning messages:
1: Please use 'rowNames' instead of 'row.names'
2: Please use 'colNames' instead of 'col.names'
Warning message:
In write.csv(vals_df, "output/gs_widetable_extreme_scalars.csv", :
attempt to set 'sep' ignored
Warning messages:
1: Please use 'rowNames' instead of 'row.names'
2: Please use 'colNames' instead of 'col.names'

Output logs successfully written!
--------------------------------------------------------------------------------
Makelog ended: 2023-11-14 19:09:41
Makelog ended: 2023-11-15 14:49:36
Working directory: /Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis
--------------------------------------------------------------------------------
10 changes: 7 additions & 3 deletions analysis/log/output_stats.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
file name | last modified | file size
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gps_scalars.csv | 2023-11-15 03:09:42 | 284
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gps_scalars.xlsx | 2023-11-15 03:09:42 | 6652
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/regression.csv | 2023-11-15 03:09:31 | 58
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gs_widetable_extreme_scalars.csv | 2023-11-15 22:49:36 | 1048
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gs_primary_scalars.xlsx | 2023-11-15 22:49:36 | 6869
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gs_primary_scalars.csv | 2023-11-15 22:49:36 | 618
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gs_widetable_scalars.xlsx | 2023-11-15 22:49:36 | 6653
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/regression.csv | 2023-11-15 22:49:31 | 58
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gs_widetable_extreme_scalars.xlsx | 2023-11-15 22:49:36 | 7038
/Users/sameernair-desai/Desktop/InstRes/SIEPR_RA/template/analysis/output/gs_widetable_scalars.csv | 2023-11-15 22:49:36 | 284
Loading

0 comments on commit e09b9f7

Please sign in to comment.