Thursday, November 25, 2010

Analyzing Stimulus Funds Data

A report from Brito & De Rugy at the Mercatus Center at GMU from earlier this year reports that (emphasis added):
"An OLS regression analysis controlling for the district representative’s political party, tenure in office, leadership position, membership on the appropriations committee, as well as for the district’s unemployment, mean income (i.e., the average income of a given wage earner in the district), and the percentage of employed persons working in the construction sector in 2008 finds that having a Republican representative decreases a district’s stimulus award by 24 percent.   This effect is statistically significant at the p < .001 level."
It's an interesting and useful paper.  They've put a lot of effort into compiling some data on the federal stimulus outlays and some other political variables as well as even correcting & error-checking the data they got from other sources. I like that they have provided the actual Stata dataset that they compiled (and they've even copied/pasted the Stata output tables in the document), but I thought that it would be interesting to run the models again with some interaction terms and clustering as well as adding in a couple of other political variables commonly used in some of the literature on Congressional pork/spending.    Looking past the chatter about the alleged political leanings of the Mercatus Center , it seemed to me that a regression model concluding that the stimulus funds where doled out by partisan lines should probably be examined a bit more closely.

First of all, I wanted to re-run their model with an interaction term for being a republican in a leadership position in a marginal seat and on the appropriations committee (republican*marginally*leadership*accountability).  My guess is that the effect of being republican might be different for those in leadership, marginal, and/or appropriations committee positions and if Democrats do have an advantage, which democrats got the biggest share (leadership, safe seats, appropriations committee members ?)-- that is, there's a bit more to the political calculus of stimulus spending than simple party lines.  
Second, I wanted to add a couple of other political variables, such as: 
  • the number and size ( in dollars) of earmarks secured by each member (No. of Earmarks & log_ttlearmarks)
  • the number of solo-authored legislation by each member (solo)
  • the number of votes and % of Democratic vote in each member's district in the prior election (log_ttlvotes & democrat_pctvote)
  • whether the governor, upper, and lower house of the member's state delegation are Republican controlled or not (governor_republican2, lower/upper_legisl_republican2)

Friday, November 19, 2010

Generating Random/Fake String Data in Stata

When posting to Statalist I usually try to provide an example of my question or answer using the in-built "auto.dta" dataset, the -input- command to manually create a dataset,  or by generating fake, random data using Stata functions.  To create fake, random numeric data, you can use any of the random number generators detailed in -help random_numbers- (such as runiform), but there is no random generator for alphabet characters (A-Z or a-z).  

Sometimes it's useful to illustrate to Statalist or students in class how to manipulate the dataset if it includes some kind of string variable that you want to use to identify panels or illustrate how to -encode- variables, etc.  (or maybe you just want a random string generator because you lost your dice for playing Scattergories)

-ralpha- generates random string characters for Stata.    In many cases, you could generate the numeric variable and -tostring- it, but if you need string (alpha) characters, this package presents an easy way to obtain them.


ralpha [newvarname] [, Loweronly Upperonly Range(string)]


upper - random alpha from uppercase letters only
lower - default; random alpha from lowercase letters only
range() -   examples include: A/Z,  a/z, A/z(uppercase is first), a/c, A/G
            - numerical range stored in `r(num_range)'
If [newvarname] is left blank, the variable "ralpha" is created (if it doesn't already exist). 


which ralpha                       //<--  see instructions

//Example 1 //
set obs 20
ralpha                           //nothing specified-new var named "ralpha" by default
ralpha lowerdefault,             //no options specified - default is lowercase
ralpha upper, upperonly
ralpha lower, low

//Example 2: Using the range() option //
**Note: range goes from a/Z (a to Z)
set obs 20
ralpha somerange, range(A/z)
ralpha, range(B/g)
    di in white "`r(num_range)'"      //Here's numerical range equiv. of "B/g"

//Example 3: create random words/strings in a loop //
set obs 50
g newword = ""
loc lnewword 5                  //how many letters in new word?
forval n = 1/`lnewword' {
ralpha new, upp
replace newword = newword + new
drop new

**make newword proper**
replace newword = proper(newword)


Tuesday, November 2, 2010

An Update to Dual

Previously I described an application/script that enabled you to open two or more Finder windows, stacked side-by-side, on Mac OSX (10.4 or later).  This update changes the proportion of the windows the the display of the files to something closer to Path Finder 5; that is, the finder window stacked on the left (Window 1 below) is set to "list view"; Finder Window 2 (right) is set to "column view."  Adjust the size of the Finder windows using the "hei"(height) and "wid"(width) properties.  The script will also "hide" all other open windows.

You can download the .app version of this file (below) and then drag it to the dock next to your icon for a convenient way to open and positioning multiple Finder windows. 

Here's the .script:

property wid : 10
property hei : 40
set the startup_disk to (path to startup disk)
tell application "Finder"
close every Finder window
set visible of (every process whose visible is true and frontmost is falseto false
         ---get the target of the 1st Finder window
                 --Window 1--
set win to make new Finder window
set the target of win to the folder "Desktop" of the home
set the bounds of win to {heiwid, (hei + 650), (wid + 750)}
set the current view of win to list view
                 --Window 2--
set win to make new Finder window
set the target of win to the folder "Documents" of the home
set the bounds of win to {(hei + 660), (wid), (hei + 1400), (wid + 750)}
set the current view of win to column view
select the last Finder window
        ----close the first Finder window
end tell