This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
=================================== | |
ROLLING WINDOW AGGREGATION IN STATA | |
=================================== | |
Problem: | |
-------- | |
Assume you have a data set with time/datestamps, noting |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import argparse | |
from pymongo import MongoClient as Client | |
from bson import BSON | |
from bson import json_util | |
import json | |
import os | |
# mongo client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
psignstars <- function(x) { | |
sapply(x, function(p) ifelse(p < .01, "***", ifelse(p < .05, "**", ifelse(p < .1, "*", " ")))) | |
} | |
# Function to run regression model (#mmix, with spec formula) | |
regmodel <- function(formula=list(~1+I(country_class=='linc') + as.factor(category) + as.factor(brand)), | |
dat, model = 'lm') { | |
lmerctrl = lmerControl(optimizer ="Nelder_Mead", check.conv.singular="ignore") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################ | |
# DOWNLOAD ENTIRE FOLDER STRUCTURE FROM DROPBOX TO LOCAL DRIVE # | |
################################################################ | |
# Instructions: | |
# (1) install dropbox API using pip | |
# > pip install dropbox | |
# (2) Create application to make requests to the Dropbox API | |
# - Go to: https://dropbox.com/developers/apps |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PROBLEM: | |
# I would like to give the new column in the new DT | |
# the name "mean_price"; however, I cannot figure out how to do this. | |
# It should be possible but I don't know how. | |
# Here is someone with a related issue: https://stackoverflow.com/questions/12391950/select-assign-to-data-table-when-variable-names-are-stored-in-a-character-vect | |
# Do you know how to resolve this issue? | |
# EXAMPLE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This gist has been replaced by an R package with an updated list of labels. | |
Get it on GitHub: https://github.com/hannesdatta/musicMetadata | |
LEGACY CODE | |
################################################# | |
# # | |
# Classify music labels # | |
# into major labels (Sony, Warner, Universal), # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#################################### | |
# # | |
# UNIT ROOT TESTS # | |
# IN THE ABSENCE OF # | |
# KNOWLEDGE ON THE ACTUAL # | |
# DATA GENERATING PROCESS # | |
# # | |
# Enders 1995, # | |
# Applied Econometric Time Series # | |
# pp. 254 - 258 and # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(stringi) | |
spelling_variants <- function(x, remove_collabs=F, remove_parentheses=T) { | |
qualifiers = c(" feat .*", " feat[.].*", " ft.*", " ft[.].*"," featuring.*"," vs[.].*"," vs.*"," versus.*"," with.*","[-].*"," / .*", | |
"/.*","[|].*", "[[].*[]]", "[)].*", ";.*","[+].*","[&] .*","[&].*",",.*"," and .*", " con .*", " e .*", " et .*", | |
" x .*") | |
# remove articles (a, the) | |
ret = gsub(" a ", "", tolower(str_trim(x))) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# TRANSFORMS A SET OF URLS TO TINY-URLS (SHORTENED URLS) | |
# adapted from https://www.geeksforgeeks.org/python-url-shortener-using-tinyurl-api/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Quick conversion of `character` date columns to Date format using data.table | |
# fread(..., colClasses = c(date='Date')) is slow for large data sets, especially when | |
# the number of unique dates is small, but the number of cross-sectional units is large. | |
# The intuition of this algorithm is to only convert the UNIQUE dates to dates using as.Date, | |
# and then merging them back to the original data.table. | |
library(data.table) | |
data.table.date <- function(dt, datecol) { |
OlderNewer