File: keane.inp

package info (click to toggle)
gretl 2016d-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 48,620 kB
  • ctags: 22,779
  • sloc: ansic: 345,830; sh: 4,648; makefile: 2,712; xml: 570; perl: 364
file content (42 lines) | stat: -rw-r--r-- 1,111 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function series mlogitlogprobs(series y, matrix X, matrix theta)
  set warnings off
  scalar n = max(y)
  scalar k = cols(X)
  matrix b = mshape(theta,k,n)
  matrix tmp = X*b
  series ret = -ln(1 + sumr(exp(tmp)))

  loop for i=1..n --quiet
    series x = tmp[,i]
    ret += (y=$i) ? x : 0 
  endloop

  return ret
end function

# Replicate the multinomial logit example from Table 15.2 in 
# Wooldridge's panel data book (2002a).
# We first do this manually using gretl's mle command, then
# show the result from gretl's built-in logit command

open keane.gdt
# for the manual variant the dep. var. must be 0-based
status = status - 1
# and we must exclude NAs
smpl (year=87 && ok(status)) --restrict

matrix X = { const, educ, exper, expersq, black }
scalar k = cols(X)
matrix theta = zeros(2*k, 1)

mle ll = mlogitlogprobs(status,X,theta)
  params theta
end mle --verbose --hessian

# Compare the built-in command (in this case we don't need
# status to be 0-based, and NAs are handled correctly)
smpl full
status = status + 1
smpl (year=87) --restrict
logit status 0 educ exper expersq black --multinomial