## Wednesday, July 2, 2008

### My new blog site

Dear readers, my blog has been moved to a new site that is hosted by the University of Minnesota:

## Tuesday, July 1, 2008

### Regression-based inequality decomposition in R

In a previous blog I posted the R functions to decompose Gini coefficients based on a weighted average of pseudo-Gini (Fei et al 1978Shorrocks 1982). Another way to decompose inequality is a regression-based approach proposed by Morduch and Sicular (2002) following the logic of Shorrock's theorem in his classic 1982 paper.

1. The R function I created

decomp <- function(M) {

n <- length(M\$coefficients)

cov <- cov(M\$model[,1],M\$model)

var <- cov[1]

cof <- M\$coefficients

share <- cov[2:n]*cof[2:n]/cov[1]

decomp <- rbind(cov[2:n],cof[2:n],var,share)

rownames(decomp) <- c("covariance","coefficient",

"variance","contribution")

decomp

}

2. An example in R results:

> M <- lm(PCEP2~PCGDP2 + POPDEN + PRIMERT, data=data)
> decomp(M)
PCGDP2       POPDEN      PRIMERT
covariance   209.4603179  -0.23886994  -0.69024676
coefficient    0.2973024 -32.81779552 -17.33004045
variance     423.0538678 423.05386785 423.05386785
contribution   0.1471989   0.01852999   0.02827537
> #. A test: The sum of contribution equals to the R square.
> sum(decomp(M)[4,]);summary(M)\$r.squared
[1] 0.1940043
[1] 0.1940043

## Sunday, June 29, 2008

### Excel2LaTeX: tricks in my Mac

This is the official introduction to Excel2LaTeX (2.0):

"It's difficult to create tables in LaTeX, especially if some columns are calculated. Excel2LaTeX tool will allow you to transform the current selection from Excel to Latex. Most of the formatting will be kept (bold, italic, border lines, multicolumn cells, etc.). The LaTeX code can be copied to the clipboard or saved as a LaTeX file, which then can be included in an existing LaTeX document using the input command."

However, the program seems to written primarily for Windows. For several reasons, it took me quite a while to get it work in my MacBook Pro. These tricks may be helpful for you too.
• The Visual Basic add-in doesn't work for Mac Excel 2008. You may use Mac Excel 2004 for the purpose.
• I manually open the xla file once in order for Excel 2004 to recognize the location for the add-in file; only then can I turn on the Excel2LaTeX button under Toolbars.
• After converting a selected area in Excel to LaTeX codes, additional tricks are needed to apply the codes. To use the clipboard function, I have to copy things to TextEdit and then recopy them to TeXShop to get them work -- otherwise, TeXshop is confused with some "invalid character." To use the "Save to File" function, I change "Desktop\Sheet1.text" to ":Desktop\Sheet1.tex" in order to get the file landed correctly in my Desktop.

## Thursday, June 26, 2008

### Calculating decomposition of Gini coefficient in R

I am working on several projects on fiscal disparities. The level of inequality can be measured by summary indices such as the Gini coefficient, but I like to move a step forward and decompose the aggregate inequality value into its relevant component contributions.

Take income inequality as an example. One way of factor decomposition is to separate the effects of multiple income streams that form the total income. It has been proposed that a Gini coefficient can be separated as multiple components based on a weighted average of pseudo-Gini (Fei et al 1978; Shorrocks 1982). With this method, for each revenue stream, we can calculate its absolute contribution, relative contribution, and marginal effect (Lerman and Yitzhaki 1985) to the inequality (Gini) of total income.

How to do this in R? Failed to find any package ("library") that can do it directly, I decided to create the function on my own by revising R codes from known packages such as ineq and reldist. It turns out to be easy and really fun!

The formulas:

An simulated example:

## Tuesday, June 24, 2008

### Archive: Weird computer problems and fixes

I got weird computer problems from time to time. Fortunately, most often I could fix them after searching on the Internet for a while. The least thing I want to happen is forgetting these solutions when I encounter the same problem again. These "wired" problems tend to be rare, but it can be indeed nerve-racking when they do show up.

1. Excel crashes with an error message "SYLK: File format is not valid" -- Excel cannot open a text or CSV file when the first two characters of the file are the letters ID (uppercase). See the link for more explanations. [06/24/2008]

2. Excel 2004 (Mac) crashed every time I opened it, as it kept opening a corrupted "recovered" file and then quitting automatically. I couldn't solve the problem even after removing and reinstalling Excel. The problem was finally fixed after I deleted "com.microsoft.office.prefs.plist" under "Users/~/Library/Preferences." Later I got to learn that it is a common solution when MS Office crashes. [06/24/2008]

3. Vmware Fusion: Windows XP failed to find shared folders. The fix is simple: go "Start" -->" Run" --> "\\.host" and press enter. [06/24/2008]

## Tuesday, June 17, 2008

### New partnership between a county and school system

As far as I know, most school districts in North Carolina are not "independent" ones; instead, they get direct funding from county governments along with other sources of revenue. NC school districts however may retain their authorities in education decision-making independent of county governments.

North Carolina NBC affiliate WNCN-TV (6/17, Hall) reports that Wake County and the county's public school systems are considering a new partnership, in which the county would take responsibility for the building and maintenance of school facilities, "if the schools receive more funding to focus on student achievement."

Without further financial details, the report is confusing to me in many ways. I wonder how exactly it will change the local funding mechanism and what are the incentives for both county and school districts to participate.

### The resurrection of urban living

The Wall Street Journal (6/16, A18, Karp) reports, increasingly, people want to live in urban areas, a change of "a half-century-long pattern of how and where Americans live," due to demographic changes and economic trends such as higher gasoline prices.

"The generational demands" of housing location from both baby boomers and millennials (those "born between the late 1970s and mid-1990s") are "in perfect sync." Getting ready to retire, baby boomers are looking to downsize their homes and simplify their lives in urban condos. Likewise, millennials are attracted by higher-density urban living, as a way of "rebelling the suburban cul-de-sac culture that pervaded their youth."

Additionally, the subprime mortgage crisis and high gasoline prices are "delivering further gut punches by blighting remote subdivisions nationwide and rendering long commutes untenable for middle-class Americans," when the used-to-be drivable surbub has become "for many a mile too far."

Some conceives that the drive for urban living may reverse the trend of urban sprawl and push for New Urbanism practices in land use and construction. Traffic behaviors will change accordingly: with the hasten demand of urban living, Americans may mimic "a European preference of public transportation."

### Outsourcing red-light traffic control

The Wall Street Journal reports that many cities are overburdened by "time-consuming and complicated tasks" and thus elect to outsource these duties to companies. Typical examples include "auctioning off unclaimed stolen goods, unloading unwanted supplies and collecting unpaid traffic fines."

In Columbus, Ohio, Redflex Traffic Systems Inc. is hired to handle "the entire process" of running the city's red-light cameras, "including capturing the visuals of the violator, cross-checking with databases from motor-vehicle departments, verifying that a violation was committed," and "mailing out the citation and collecting the fine." In exchange, the company "receives about 40 percent of the actual fines collected."