Skip to content

Instantly share code, notes, and snippets.

#%%
from google.cloud import translate_v2
from googletrans import Translator
import os
from pathlib import Path
import pandas as pd
# %%
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] ="/home/alal/keys/sandbox-7f8884d01b79.json"
translate_client = translate_v2.Client()
@apoorvalal
apoorvalal / OLS_and_Probit_w_FEs.R
Created July 19, 2021 16:29
minimal example of binary outcome regression with fixed effects using OLS and probit
# %% ####################################################
library(alpaca); library(fixest)
# %% ####################################################
data(psid, package = "bife")
head(psid)
# %% https://cran.r-project.org/web/packages/alpaca/vignettes/howto.html
stat <- alpaca::feglm(LFP ~ KID1 + KID2 + KID3 + log(INCH) | ID + TIME, psid, binomial("probit"))
# Fernandez-Val + Weidner bias correction - https://www-sciencedirect-com.stanford.idm.oclc.org/science/article/pii/S0304407615002997?via%3Dihub
stat.bc <- biasCorr(stat)
@apoorvalal
apoorvalal / Attack_2_to_3.R
Last active July 12, 2021 06:00
do policies to increase attack in football work?
# %% ####################################################
rm(list = ls())
library(LalRUtils)
LalRUtils::libreq(tidyverse, data.table, fst, collapse, fixest, rio, foreach, magrittr,
janitor, tictoc, modelsummary, hablar, patchwork, RPushbullet, IRdisplay,
did, panelView)
theme_set(lal_plot_theme()) # add _d() for dark
options(repr.plot.width=12, repr.plot.height=9)
options(ggplot2.discrete.fill = RColorBrewer::brewer.pal(7, "Set2"))
options(ggplot2.discrete.colour = RColorBrewer::brewer.pal(7, "Set2"))
@apoorvalal
apoorvalal / read_write_sqlite_pandas.py
Created June 23, 2021 16:10
example of sqlite <> pandas interop
import pandas as pd
import sqlite3
# %%
Cars = {'Brand': ['Honda Civic','Toyota Corolla','Ford Focus','Audi A4'],
'Price': [22000,25000,27000,35000]
}
df = pd.DataFrame(Cars, columns= ['Brand', 'Price'])
print (df)
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
https://conda.anaconda.org/conda-forge/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/blas-1.0-openblas.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2020.6.24-0.conda
https://repo.anaconda.com/pkgs/main/linux-64/ld_impl_linux-64-2.33.1-h53a641e_7.conda
https://repo.anaconda.com/pkgs/main/linux-64/libgfortran-ng-7.3.0-hdf63c60_0.conda
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-9.1.0-hdf63c60_0.conda
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 5.
"","Package","LibPath","Version","Priority","Depends","Imports","LinkingTo","Suggests","Enhances","License","License_is_FOSS","License_restricts_use","OS_type","MD5sum","NeedsCompilation","Built"
"abind","abind","/home/alal/R/x86_64-pc-linux-gnu-library/3.6","1.4-5",NA,"R (>= 1.5.0)","methods, utils",NA,NA,NA,"LGPL (>= 2)",NA,NA,NA,NA,"no","3.6.2"
"acepack","acepack","/home/alal/R/x86_64-pc-linux-gnu-library/3.6","1.4.1",NA,NA,NA,NA,"testthat",NA,"MIT + file LICENSE",NA,NA,NA,NA,"yes","3.6.2"
"AER","AER","/home/alal/R/x86_64-pc-linux-gnu-library/3.6","1.2-9",NA,"R (>= 3.0.0), car (>= 2.0-19), lmtest, sandwich (>= 2.4-0),
survival (>= 2.37-5), zoo","stats, Formula (>= 0.2-0)",NA,"boot, dynlm, effects, fGarch, forecast, foreign, ineq,
KernSmooth, lattice, longmemo, MASS, mlogit, nlme, nnet, np,
plm, pscl, quantreg, rgl, ROCR, rugarch, sampleSelection,
scatterplot3d, strucchange, systemfit (>= 1.1-20), truncreg,
tseries, urca, vars",NA,"GPL-2 | GPL-3",NA,NA,NA,NA,"no","3.6.2"
"alpaca","alpaca","/home/alal/R/x86_
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@apoorvalal
apoorvalal / cbooker.do
Last active April 13, 2022 19:58
walk through dir with stata files and export codebook
*! v0.1 Apoorva Lal
// returns dataset with dataset's <describe> output
// useful for very wide datasets / datasets with useless/uninformative
// variable names
// e.g. USAID's Demographic and Health Surveys
pr define varlabelbook
syntax [anything]
qui compress
qui ds `anything'
#!/bin/bash
#SBATCH --job-name=cron
#SBATCH --begin=now
#SBATCH --dependency=singleton
#SBATCH --time=00:02:00
#SBATCH -p hns
#SBATCH --mem-per-cpu=4GB
#SBATCH --mail-type=FAIL
# module loads