# DESCRIPTION

This package estimates a logit model for (possibly unbalanced) panel
data, with fixed effects, via Chamberlain's conditional ML
estimator. See for example Cameron & Trivedi (2005),
"Microeconometrics", section 23.4.3.

# AVAILABLE FUNCTIONS

It contains three functions, described below.

## felogit(series depvar, list X, scalar verbose[0], bool time_dummies[0])

Arguments:

- depvar: series, dependent variable (must be binary)
- X: list, explanatory variables for main equation
- opts: bundle, user options (described below)

Returns a bundle with the estimation results. This function performs
estimation of the model by using analytical derivatives. The
covariance matrix of the parameters id computed as the inverse
Hessian. WARNING: estimation may be rather demanding in terms of
memory requirements and CPU load, especially if the time dimension of
the panel _T_ exceeds 16 time periods.

## felogit_ahat(series depvar, list X, bundle b, bool biascorr)

- depvar: series, dependent variable (must be binary)
- X: list, explanatory variables for main equation
- b: bundle created by the felogit() function
- biascorr: use the Bartolucci-Pigini bias correction
     
This function returns a series containing the estimated individual
effects. The third argument, in fact, need only contain a vector named
"coeff" with as many elements as the list X; therefore, a bundle
containing the output of the felogit() function is perfectly suitable,
but a bundle constructed "by hand" will do as well.

The method employed is explained in detail in Bartolucci-Pigini (2019),
"https://mpra.ub.uni-muenchen.de/92251/5/MPRA_paper_92251.pdf", especially
section 3.1.1.

The details of the computations depend on the value of the "biascorr"
parameter. If biascorr is 0, the plain ML estimates are returned; if
it is 1 (the default) then a bias correction is applied. Note that, if
biascorr is 1, estimated individual effects will be computed for all
units in the currently selected sample, while if biascorr is 0 units
for which the dependent variable is time-invariant will be excluded.

## felogit_print(bundle *b)

- b: pointer to bundle created by the felogit() function

returns nothing; this function is simply meant to print out separately
the results for a model estimated previously via felogit().

# OPTIONS

The option bundle that "felogit" accepts can contain the following
keys:

- algo: scalar, 1 or 2, algorithm used for computing the
  log-likelihood (1="matrix", 2="recursive")
- do_ahats: scalar, 0 to 2 (compute individual effects (0 = Don't, 1 =
  With bias correction, 2 = without bias correction; default = 0)
- timedums: Boolean (add time fixed effects)
- verbose: scalar, 0 to 2, verbosity level (0 = print nothing, 1 = print
  results only, 2 = print ML iterations; default: 1)

If the do_ahats argument is non-zero, estimated individual effects will
be stored in the output bundle under the "ahat" key (see also below).

## algorithm details

With "algo"=1, the log-likelihood is computed by creating per-unit
Boolean matrices listing on each row all the possible combinations of
_k_ ones from _T_ observations, using the "binperms" hansl
functions. This is normally quite fast, but comes at the cost of
larger memory requirements, especially when _T_
exceeds 16. Optimisation is carried out via Newton-Raphson.


With "algo"=2, the recursive algorithm devised by Gail et al. (1981),
Biometrika, Vol. 68, No. 3 is used. Optimisation is carried out via LBFGS.

# CHANGELOG

2.1 -> 3.0: **This version of the package is mildly backward-incompatible**, on account of changes to the signature of the main function (arguments from 3 onwards have been replaced by an option bundle).  
Moreover, the "recursive" method for computing the loglikelihood is now available and help file was switched to the markdown format.

2.0 -> 2.1: Small but decisive (in terms of efficiency) internal
    change. Nothing has changed, except the function should now be
    much faster, especially for panels with many units.

1.91 -> 2.0: main addition: estimation of individual effects via
    felogit_ahat(). No other user-visible changes.

1.9 -> 1.91: robustify the panel_acct as per Sven's suggestion; also: trim 
    some cruft and adds a few comments here and there.

1.8 -> 1.9: Fix naming bug (felogit would fail if there was a regressor
    named "y" --- not a real fix, but it should do): while at it, modernize
    syntax, robustify a few checks and add a few comments.

1.7 -> 1.8: fix menu attachment and switch, internally, to a matrix
    array representation for the Q matrices instead of a big bundle
    (marginally more efficient, certainly cleaner).

1.6 -> 1.7: one-line change to work around a bug in the psd() function
    in gretl 2018b; check for time-invariance in the dependent variable

1.5 -> 1.6: no substantial changes. The private functions isdummy()
    and minimal() were replaced by their native equivalents isdummy()
    and dropcoll(); minimal touches to the help file. Also, the sample
    script was updated.
