Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Applied Logistic Panel Regression

    Hello community,

    I am currently working on a time series analysis and constructing a prediction model. In my logistic regression model from 2000 to 2008 different independent variables shall be included. My problem here: a few of the independent variables should be included over the entire period (var3 & var4 are time invariant) and two independent variables (var1 & var2) should only be included in the regression from the period 2001 to 2008. I already read something about this in the forum, but only the Lagged and Lead command was explained here. But I don't think that this is applicable here, because the data will only be moved, but I want to keep it in that respective year. My current code is:

    xtlogit depvar var1 var2 var3 var4 var5, re

    Due to the missing data of var1 and var2 in the year 2000, STATA eliminates the 2000 year column and only includes the rest in the regression. Can someone kindly help me with the code to avoid this?

    many thanks in advance!!




    the following shows the course of the variables over time for one selected observation (a person)

    Click image for larger version

Name:	1.PNG
Views:	1
Size:	9.3 KB
ID:	1504878

  • #2
    Your attempt to show example data is appreciated, but isn't helpful. The helpful way to show example data is with the -dataex- command. If you are running version 15.1 or a fully updated version 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    It is also not helpful because you say you are running -xtlogit-, but the example you show does not have any panel or serial cross-sectional structure.

    When asking for help with code, always show example data. When showing example data, always use -dataex-

    Since I couldn't use your example data, I'm illustrating the technique here using one of StataCorp's web data sets, modified to have missing values of one variable in a certain time period, but not others.

    Syntactically, you cannot have a model in which a variable is entered in the model for some observations but not for others. And you also cannot cajole Stata into including in its calculations any observation that contains a missing value for any variable in the model. So to work around these constraints, you need to provide placeholder numbers as a substitute for the missing values in those observations where the variable is not wanted, and then, you must enter the variable into the model. But you enter it interacted with a variable that indicates which years the variable is to be included for, and you constrain the coefficient for the non-included years part of the interaction to 0. After all, constraining a coefficient to 0 is equivalent to excluding the variable from the model.

    Code:
    //    MODIFY A STATACORP DTA SET TO RESEMBLE THE PROBLEM AT HAND
    webuse nlswork, clear
    replace tenure = . if year <= 77
    
    //    NOTICE THAT YEARS 77 AND EARLIER ARE EXCLUDED FROM THE MODEL
    //    ROUTINELY
    xtlogit union ln_wage tenure, re
    tab year if e(sample)
    
    //    WORKAROUND
    assert tenure >= 0
    replace tenure = -9999 if year <= 77
    gen byte pre_post = year > 77
    
    constraint define 1 0.pre_post#tenure = 0
    xtlogit union ln_wage i.pre_post#c.tenure, re constraint(1)
    
    tab year if e(sample)
    You can modify this code to solve your specific problem.

    Comment

    Working...
    X