MDC code

June 16, 2009 at 5:04 am 1 comment

| Gabriel |

A reader requested that I post some code relevant to the multilevel diffusion curve (MDC) method I published in Sociological Methodology. I have code for both the more primitive techniques we discuss in the lit review and our new MDC technique, but neither script is as elegant as it should be.

I’ve already posted code to do the precursor approach by Edwin Mansfield, though I recently learned some matrix syntax that will let me rewrite it to run much more cleanly when I find a chance to do so. The problem with the current version is that it makes extensive use of writing to disk and POSIX commands via “shell.” On Mac/Linux this is ugly but perfectly functional, but it won’t work at all on Windows (at least not without CygWin). I hope to rewrite it to be more elegant and completely self-contained in Stata, but this is a luxury as the current ugly version works on my Mac.

Likewise, I have code (posted below) to do MDC, but it’s also less than ideal. MDC doesn’t regress anything interesting directly, but first runs a regression (“table 2” in the paper) and then uses the quadratic equation to make the results intelligible (“table 3” in the paper). The problem is that my Stata code only does the first step. To do the second half you need to take the output and put it in this Excel spreadsheet. I’m hoping to rewrite it so that the command produces useful output directly but this is easier said than done as it requires a lot of saving returned results, matrix multiplication, and other things that are somewhat difficult to program.

Anyway, in the meantime, here’s the code. It follows a syntax similar to xtreg. In addition to “i” you also specify “nt” which means adoptions to date.

capture program drop mdcrun
program define mdcrun
	set more off
	syntax varlist , i(string asis) nt(string asis) 

	disp "This code gives information which must be interpreted"
	disp " with the spreadsheet at"
	disp "comments in this output give hints on how to use the spreadsheet"

	gettoken first varlist : varlist

	gen cons=1
	foreach var in `varlist' cons {
		quietly gen `var'_1=`nt'*`var'
		quietly gen `var'_2=`nt'*`nt'*`var'

	foreach var in `varlist' cons {
		local varlist_ext="`varlist_ext' `var' `var'_1 `var'_2"

	* create `varlist_ext' as an alternate varlist macro that has the interactions

	disp "-------------------------------"
	disp "Columns M+J, mean and sd"
	sum `varlist'

	disp "-------------------------------"
	disp "put the baseline beta+sd model in J7:N5"
	xtreg `first' `varlist', re i(`i')
	disp "-------------------------------"
	disp "coefficients are vars + interactions with nt and nt^2"
	disp "additive beta+se in J and K"
	disp "var_1 beta+se in L and N"
	disp "var_2 beta+se in T and V"
	disp "Please see AC-AJ for interpretation"
	xtreg `first' `varlist_ext', re i(`i')
	disp "-------------------------------"
	disp "For citation and help with theory/interpretation, see"
	disp `"Rossman, Chiu, and Mol. 2008. "Modeling Diffusions of"'
	disp "Multiple Innovations Via Multilevel Diffusion Curves:"
	disp `"Payola in Pop Music Radio" Sociological Methodology"'
	disp "38:201-230."


Entry filed under: Uncategorized. Tags: , .

Clara est la fille de Sophie Bride of True Tales of the IMDB!

1 Comment

The Culture Geeks

%d bloggers like this: