File: keane.inp

package info (click to toggle)
gretl 2022c-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 59,552 kB
  • sloc: ansic: 409,074; sh: 4,449; makefile: 3,222; cpp: 2,777; xml: 599; perl: 364
file content (42 lines) | stat: -rw-r--r-- 1,101 bytes parent folder | download | duplicates (2)
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 i=1..n
    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