Tag Archives: PostgreSQL

Incorporating SQL in Stata code

Here is a snippet of code showing how one can include SQL in Stata code (I assume that the ODBC connection has been set up). #delimit ; local sql ” SELECT * FROM director_bio.directorship_results WHERE non_match AND start_date < date_filed … Continue reading

Posted in PostgreSQL, Stata, Uncategorized | Tagged , , | Leave a comment

Prototyping PL/Python functions

I’ve seen a variable called numerical intensity crop up in a couple of papers recently (one example is Lundholm, Rogo, and Zhang (2014)). I spent a little time coming up with a Python program to extract numbers from text. Once … Continue reading

Posted in PostgreSQL, Python | Tagged , , , , | Leave a comment

Upgrading PostgreSQL from 9.4 beta1 to 9.4 beta2

MacPorts installs PostgreSQL 9.4 beta2 in the same directory as PostgreSQL 9.4 beta 1 was in. And going from beta 1 to beta 2 requires an upgrade for the cluster to work. So upgrading is more like going from 9.3 … Continue reading

Posted in Mac, PostgreSQL | Tagged , , | Leave a comment

Get “tone” from corporate disclosures: PostgreSQL, Python, and R.

The paper by Loughran and McDonald (2011) develops lists of words that are intended to reflect “tone” in financial text. The following code retrieves these lists and applies them to a large body of text (over a billion words) from … Continue reading

Posted in Uncategorized | Tagged , , , , , , , | 4 Comments

Using JSON to pass dictionaries from Python to PostgreSQL and back

To my (very untrained) eyes, JSON looks like Python dictionaries. I’d wondered if one could use JSON to pass around Python dictionaries. Turns out that it works quite well. Task Get the top N words from passages of text (conference … Continue reading

Posted in PostgreSQL, Python | Tagged , , , , | 1 Comment

RPostgreSQL (R) versus psycopg (Python)

Here’s a rather simplistic comparison of the performance of R and Python in getting data from PostgreSQL. R: Time taken: 26-27 seconds. Python: Time taken: Around 6 seconds. I’m impressed. I’ve never really been bothered by performance in getting data … Continue reading

Posted in PostgreSQL, R | Tagged , , | Leave a comment

Using PL/R for quantiles

I was trying to reproduce a plot from a book today. The plot has quantiles (10th, 25th, 50th, 75th, and 90th percentiles) for market-to-book for US companies from 1963 through 2010. I wanted to pull the data together in PostgreSQL, … Continue reading

Posted in PostgreSQL | Tagged | Leave a comment

Perl script to pull SAS data from WRDS and put it into a local database

Usage: ./get_SAS_data.pl library datafile (for example, ./get_SAS_data.pl comp funda. This code doesn’t work with some files (e.g., CRSP daily stock file) due to the way that SAS PROC EXPORT handles special missing values (essentially converts “.A” to “A”, which PostgreSQL … Continue reading

Posted in Perl, PostgreSQL | Tagged | 3 Comments

Install PL/R on OS X 10.8.4

To get PL/R working on OS X 10.7.4, I had to reach out to the PL/R community for assistance (note something like sudo apt-get install postgresql-9.1-plr postgresql-server-dev-9.1 is all that is needed with Ubuntu). I just (on 2013-06-10) installed on … Continue reading

Posted in Mac, PostgreSQL | Tagged | 1 Comment

New feature of PL/R: WINDOW functions

PL/R is module that allows PostgreSQL to access R functionality. Here is an illustration of a feature recently added to PL/R. This is meant to represent a “panel” of ten-year time series for 100 firms numbered 1 through 100. I … Continue reading

Posted in Uncategorized | Tagged | Leave a comment