Advanced Database Tricks for Social Scientists – Querying a SQL Database in Stata

This is a quick guide to setting up a connection to directly query an ODBC-compliant database from a do file in Stata.

NOTE: As the title suggests, this guide assumes relatively advanced knowledge of both relational databases (e.g. Oracle, SQL Server, MySQL, etc) and Stata.  Viewer discretion advised.

OBJECTIVE: Use a Stata do file to directly query a live ODBC-compliant, relational, T-SQL database and load the results as the current dataset in Stata.  Do this using a connection string so no OS-specific named ODBC datasources are required.

Step 1 – Make sure you have a working connection to your database server of choice (and have the appropriate permissions and access)

Step 2 – Assemble the following information to use in creating a connection string.

Step 3 – Use the following code in your Stata do file

*** LOAD DATA ***
// clear any data already loaded in memory
clear

//database connection
local db = "DRIVER={YOURDRIVERNAMEHERE};SERVER=yourservernameoripaddress;DATABASE=databasename;UID=uid;PWD=pwd;"

// SQL SELECT statement to retrieve data
local sql = "SELECT * FROM YourTable"

// Load data via ODBC (using connection string)
odbc load, exec("`sql'") connectionstring(“`db'") clear

//destring any vars that came in as strings but should be numeric
destring, replace

 

The driver attribute in the connection string is the full name of the driver as your OS sees it when installed. For example, when I connect to MySQL, I use the following

DRIVER={MySQL ODBC 5.3 Unicode Driver}

You can find the driver name by checking your ODBC drivers using a command line (WIN/OSX/Linux) or with a GUI through the ODBC settings in your control panel (WIN) or by installing the iODBC GUI (OSX/Linux) available at: http://www.iodbc.org/dataspace/iodbc/wiki/iODBC/Downloads

Coming Soon: In a former life, I was a software engineer, IT project manager, and database developer. I built software and worked with enterprise-level database tools on a daily basis for about a dozen years before getting my PhD and becoming a full-time researcher and teacher in the field of Management and Entrepreneurship.  When my fellow academics learn this part of my history, they often ask me for advice in learning how to better manage the data they use for social science research.  So, I’ve decided to post a series of tutorials (not sure whether they’ll be articles, videos, or both) giving an introduction to how an ordinary social scientist can use the kinds of high-horsepower tools that software and database engineers use every day.  Stay Tuned.

Book Chapter – The Role of Personal Values in Social Entrepreneurship

My first book chapter just hit the press.

I wrote Chapter 4: The Role of Personal Values in Social Entrepreneurship in Patterns in Social Entrepreneurship Research Edited by Jill Kickul and Sophie Bacq

In this chapter, I examine the question of how an entrepreneur’s values influence the kind of venture s/he will create. I draw on values theories from social psychology to explain the role of values as drivers of entrepreneurial action with the purpose of creating social or environmental benefits over and above economic benefits. I argue that entrepreneurs will place varying levels of priority on values focused on either self-enhancement or self-transcendence and that these prioritizations will strongly influence the importance they place on creating economic or social benefits through their ventures. I provide a framework for understanding how values motivate social entrepreneurs to create non-economic value.

Citation: Conger, M. 2012. The Role of Personal Values In Social Entrepreneurship. In J. Kickul & S. Bacq (Eds.), Patterns in Social Entrepreneurship Research: 87–109. Northampton, MA: Edward Elgar.

Article – I Am Joplin: Community Identity And Entrepreneurship After Natural Disasters

The paper I wrote with Jenni Dinger and Carla Bustamante for the 2012 SEE Conference and 2012 Babson Conference, I Am Joplin: Community Identity And Entrepreneurship After Natural Disasters, was accepted for publication in the 2012 Frontiers of Entrepreneurship Research. It should be available in print sometime in late 2013.

This paper explores non-financial contributors to an entrepreneur’s decision-making process regarding reinvestment following a natural disaster. Existing literature regarding natural disasters has focused on the financial determinants at the near exclusion of social-psychological variables, leaving a gap in the literature that our empirical study aims to address. We hypothesize that the rebuilding process of a business after a natural disaster is driven not only by economic considerations, but also by the extent to which an entrepreneur feels connected and entwined to her community. We measure social identity of an entrepreneur by focusing on the dimensions of group attractiveness and interdependency beliefs. Our overarching proposition is that entrepreneurs with a stronger collective social identity are more likely to rebuild following a widespread natural disaster.

We find support for our theory in a survey of 112 owners of businesses destroyed in a tornado- impacted Midwest community eight months after the natural disaster. Our results indicate that the constructs of interdependency belief and group attractiveness have a significant relationship with the entrepreneur’s decision to rebuild over and above financial considerations.

Citation: Dinger, Jennifer, Michael Conger, Carla Bustamante, 2012. “I Am Joplin: Social Identity, Entrepreneurs, and Environmental Disasters.” Frontiers of Entrepreneurship Research, Babson College, Wellesley, MA.
Image Credit – “Restore Joplin” by Doug Wertman, used under CC BY 2 / Cropped from original