Skip to content

Instantly share code, notes, and snippets.

How to write programs (also called commands or functions) in Stata

This is an introduction to how to write programs in Stata. To try this out yourself, download this Gist by clicking Download Zip. Unpack the .zip file and edit the path global in the runfile.do. Then follow these instructions and run the corresponding section of the run file.

If you have any questions or want us to add another examples on how you can expand myhist.ado as us in the comment section below.

Hello World

It is common in computer science that the first function/command you write is a simple command that just display the message Hello World!. That is what the program in hello_world.ado does.

@j-k-projects
j-k-projects / Add-sub-functions.md
Created June 22, 2019 08:32 — forked from kbjarkefur/Add-sub-functions.md
How to have to commands in seperate ado-files sharing the same sub-commands in a separate file.

Two commands sharing the same sub-functions

It is common that two ado-files in the same package share a lot of sub-commands (also called utility commands, functions etc.). It is bad practice to write the commands in one file first and copy and paste the sub-commands to the other ado-file. This is ad practice as updating these commands is very likely to lead to errors. This is a part of the DRY coding principle that is one of the few coding paradigms that all computer scientists agrees on.

This Gist explains how you can set this up in a Stata environment.

The mySubCommandsXYZ.do file

You should give this file a unique name if you are planning on publishing commands using this method as there will be a name conflict if someone else also have a file called mySubCommandsXYZ.do or whatever you end up calling your file.

This file includes all sub-commands that should be included in the ado-files for the commands. The commands in this file may not have

@j-k-projects
j-k-projects / qsf_explanation.md
Created July 19, 2019 21:41 — forked from ctesta01/qsf_explanation.md
How does a Qualtrics Survey File work?

Quickstart Guide to undertsanding the Qualtrics Survey File

This information is likely to quickly become outdated when Qualtrics next changes the formatting of the QSF file. This guide was started February 2017. I hope that it is a useful introduction to understanding the contents of the QSF file that one can download from Qualtrics.

This document includes:

@j-k-projects
j-k-projects / nflscrapr.md
Created November 8, 2019 23:08 — forked from guga31bb/nflscrapr.md
Simple guide for using nflscrapR

Basic nflscrapR tutorial

I get a lot of questions about how to get nflscrapR up and running. This guide is intended to help new users build interesting tables or charts from the ground up, taking the raw nflscrapR data.

Quick word if you're new to programming: all of this is happening in R. Obviously, you need to install R on your computer to do any of this. Make sure you save what you're doing in a script (in R, File --> New script) so you can save your work and run multiple lines of code at once. To run code from a script, highlight what you want, right click, and select Run line. As you go through your R journey, you might get stuck and have to google a bunch of things, but that's totally okay and normal. That's how I wrote this thing!

A huge thank you to Josh Hornsby (@Josh_ADHD) and Zach Feldman (@ZachFeldman3) for sharing code snippets for me to work with, and of course to the nflscrapR team ([Maksim Horowitz](https://twit

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@j-k-projects
j-k-projects / play_by_play_python.md
Created November 8, 2019 23:11 — forked from Deryck97/play_by_play_python.md
An introduction to working with nflscrapR data in Python

nflscrapR Python Guide

This is an introduction to working with nflscrapR data in Python. This is inspired by this guide by Ben Baldwin.

Using Jupyter Notebooks which comes pre-installed with Anaconda is typically the best way to work with data in Python. This guide assumes you are using the Ananconda distribution and therefore already have the required packages installed. If you are not using the Anaconda distribution, install both Pandas and Matplotlib.

Collecting Data

Ben Baldwin again has provided a great tutorial, so follow this to get season or game data into a csv.

Note: scraping a whole season's worth of data took at least two hours for me, you may be better off going [here](https://github

An Alternate Approach to Measuring the Effect of Accumulated QB Hits on Passing Performance

This analysis is a follow-up to @benbbaldwin's post The accumulation of QB hits vs passing efficiency where his conclusion was that:

[For] a given level of hits, there is no evidence that the accumulation of hits makes any difference throughout the course of a game.

As the title suggests, this analysis will take a different approach to measuring the hypothesized effect.

1. Data

Here is the code to get the passing data we'll be using from nflscrapR-data:

@j-k-projects
j-k-projects / pollscore.m
Created November 8, 2019 23:54 — forked from akeaswaran/pollscore.m
Calculating poll score in CFC
-(void)updateStrengthOfWins {
int strWins = 0;
for ( int i = 0; i < gameSchedule.count; ++i ) {
Game *g = gameSchedule[i];
if (g.homeTeam == self) {
strWins += pow(60 - g.awayTeam.rankTeamPollScore,2);
} else {
strWins += pow(60 - g.homeTeam.rankTeamPollScore,2);
}
}
@j-k-projects
j-k-projects / gist:17ae016e541c1929e96e80363212c4e1
Created November 9, 2019 00:02 — forked from Robotto/gist:9db27ceead01c3ce7ece6406881f8c92
Schedules & Scores API for Streaming Live Sports Stats - MSNBC
import pytz
import datetime
import time
import urllib2
import json
import os
import elementtree.ElementTree as ET
url = 'http://scores.nbcsports.com/ticker/data/gamesNEW.js.asp?jsonp=true&sport=%s&period=%d&random=%d'