Bass projections

March 18, 2009 at 5:30 pm 1 comment

| Gabriel |

I deal a lot with the Bass model, which divides the hazard function into an exogenous and endogenous component. As such I often need to draw Bass functions with particular parameters that are either purely hypothetical or based on a regression analysis (such as my MDC technique). I used to do this in a spreadsheet, but I wrote this Stata program  to automate it.

Here’s the syntax to create a basic s-curve:

bassproject s 0 .2 1 .01 50 graph

Here’s the program:

capture program drop bassproject
program define bassproject
 set more off

 local modelname `1'
 local a `2'         /*constant hazard*/
 local b `3'         /*endogenous hazard*/
 local nmax `4'      /*asymptote of adoption*/
 local seed `5'      /*adoptions at t_0*/
 local periods `6'   /*how long should the diffusion run?*/
 local graph `7'     /*enter "graph" to create a line graph*/

 set obs `periods'
 gen t=[_n]-1
 gen Nt=.
 gen deltan=.
 replace Nt=`seed' in 1
 replace deltan=(`a' + (`b' * Nt)) * (`nmax' - Nt) in 1
 forvalues period=2/`periods' {
  replace Nt=Nt[_n-1]+deltan[_n-1] in `period'
  replace deltan=(`a' + (`b' * Nt)) * (`nmax' - Nt) in `period'
 sort t
 ren Nt nt_`modelname'
 drop deltan
 save projection_`modelname', replace
 if "`graph'"=="graph" {
  twoway line nt_`modelname' t
  graph export projection_`modelname'.png, replace

Entry filed under: Uncategorized. Tags: , .

Publication bias Append to nothing

1 Comment

  • 1. NetLogo « Code and Culture  |  July 9, 2010 at 2:29 pm

    […] the tutorial, I was able to write the script below, which is kind of a replication of an older Stata script. The really exciting thing though is that NetLogo makes it much easier to do simulations with […]

The Culture Geeks

%d bloggers like this: