Tuesday, November 27, 2012

Survival analysis using Stata

Survival analysis using Stata

Monday, November 19, 2012

Stata Programming

Stata programming
      • di "`2+2'" // ==> N/A
      • local x 2
        • di "`=`x'-2'" // ==> 0
      • local pth "c:\project"
        • di "`pth'\data\" //==> "c:\project\data\"
      • global pt "c:\project"
        • di "$pt\data\" //==> "c:\project\data\"
        • di "${pt}data\" //==> "c:\projectdata\"
      • local a 2+3
      • local b 7
        • display `a'+`b' //==> 10
        • display "`a'+`b'" //==> 2+3+7
        • display "`a'"+"`b'" //==> 2+3+"7" invalid name
        • display "`a'""+""`b'" //==> 2+3+7
      • regress mpg weight
        • local rsqf e(r2)
        • local rsqv = e(r2)
        • di "R-squared_1f=`rsqf'"  //==> R-squared_1f=e(r2)
        • di "R-squared_1v=`rsqv'"  //==> R-squared_1v=.6515312529087511
        • di "R-squared_2f=" `rsqf' //==> R-squared_2f=.65153125
        • di "R-squared_2v=" `rsqv' //==> R-squared_2v=.65153125
        • di "R-squared_3f=" "``rsqf''" //==> R-squared_3f=.6515312529087511
        • di "R-squared_3v=" "``rsqv''" //==> N/A
  • Stata Blog: Programming an estimation command in Stata
      • Example 1: Storing and extracting the result of an extended macro function
        • local count : word count a b c
        • display "count contains `count'" ==> count contains 3
      • Example 2: Using gettoken to store first token only
        • local mylist y x1 x2
        • display "mylist contains `mylist'" ==> mylist contains y x1 x2
        • gettoken first : mylist
        • display "first contains `first'" ==> first contains y
      • Example 3: Using gettoken to store first and remaining tokens
        • gettoken first left: mylist
        • display "first contains `first'" ==> first contains y
        • display "left  contains `left'" ==> left  contains  x1 x2
      • Example 4: Local macro update
        • local p = 1
        • local p = `p' + 3
        • display "p is now `p'" ==> p is now 4
      • Example 5: Local macro update
        • local p = 1
        • local ++p
        • display "p is now `p'" ==> p is now 2

Friday, November 16, 2012

The rule of thumb: AIC preference/signficance levels

The rule of thumb: AIC and BIC preference/signficance levels

The Akaike information criterion (AIC) is a measure of the relative goodness of fit of a statistical model, which was developed by Hirotsugu Akaike in 1974. It was not much appreciated until 21 century. Now it’s one of the most used fit statistic output for statistical modeling. The preferred model is the one with the minimum AIC value; however, there are no statistic test for model choice based on this criterion. I found a table in Joseph M Hilbe’s book (Negative Binomial Regression, 2nd Ed, 2011) which may help us to choose a better model. Below is a table I modified based on his confusing table:

AIC = -2(log-likelihood) + 2(number of predictors including the intercept)
========================================
AIC of (Model A – Model B) ,  if AIC(A) > AIC(B)
----------------------------------------------------------------
< 2.5            No difference in models
2.5 – 5.9      Prefer B if sample size n > 256
6.0 – 9.9      Prefer B if sample size n > 64
≥ 10.0          Prefer B
========================================

Another criterion measure is Bayesian information criterion (BIC). Raftery AE (1995) gave the scale for relative preference of two models (I modified the table in Hilbe's book):

BIC = -2(log-likelihood) + (number of predictors including the intercept)*(ln(sample size))
========================================
BIC of (Model A – Model B) ,  if BIC(A) > BIC(B)
----------------------------------------------------------------
< 2.0            Weak
2.0 – 5.9      Positive and prefer B
6.0 – 9.9      Strong and prefer B
≥ 10.0          Very strong and prefer B
========================================

Sunday, November 11, 2012

Gardening and Cooking


Gardening


Cooking
Restaurants
Others



Thursday, November 01, 2012

Resource and Tips of Stata

Resource and Tips of Stata