Announcement

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

  • dynamic imputation and replacing imputed values

    Dear all,

    it´s my first time working with mi impute and I´m a bit confused how to use the data generated by mi impute.

    I have got a large panel dataset with 12,000 individuals in which I want to impute missing data for the ears between 1986 and 2010.

    My data structure looks like this:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long id int syear float(work_status flag_impu_work) byte(transition_work _mi_miss) float(_1_transition_work  _2_transition_work  _3_transition_work  _4_transition_work) byte(_5_transition_work _6_transition_work)
    01 1986 1 0 0 0 0 0 0 0 0 0
    01 1987 1 0 0 0 0 0 0 0 0 0
    01 1988 1 0 0 1 0 0 0 0 0 0
    01 1989 1 1 . 1 . . . . . 0
    01 1990 . 0 . 1 . . . . . .
    01 1991 . 0 . 1 . . . . . .
    02 1986 1 0 0 0 1 1 1 1 1 1
    02 1987 1 0 1 0 0 0 0 0 0 0
    02 1988 0 0 0 1 0 0 0 0 0 0
    02 1989 0 1 . 1 . . . . . 0
    02 1990 . 0 . 1 . . . . . .
    02 1991 . 0 . 1 . . . . . .
    end

    Now I want to to implement a dynamic microsimulation model which uses the information I have in t-1 to impute whether a person changes their employment status in t.
    The variable "transition" indicates whether a person changes their employment status in the next period.

    So here in the example I want to use information from 1989 to impute the employment status in 1990.

    Now I want to write a loop implementing this. My code so far looks like this:


    Code:
    mi set wide
    
    mi register imp transition_work
    
    mi register regular age age2 age3 edu_highest migration region
    
    *** START LOOP
    
    forval y=1986/2012 {
    
        capture drop flag_impu_work
        
        gen flag_impu_work =0
         
        #d;
        sort pid syear;
        by pid: replace flag_impu_work=1 if syear==(`y'-1) & work_status!=. & work_status[_n+1]==. & id==id[_n+1] & year_last_observation<=(`y') & syear>=entry+1;
        
    
        
            mi impute logit transition_work =  c.age c.age2 c.age3 i.edu_highest i.migration i.region if syear==`y'-1 & work_status!=. , noisily rseed (1234) add(1) augment iterate(100);
                          
    #delimit cr
    
    * updating information
    
    * replace missing value in t with imputed value
    
      replace transtion_work = _6_transition_work if syear== `y' & transition_work ==. & _6_transition_work !=. & flag_impu_work==1
        
    * update employment status
    replace work_status=work_status[_n-1] if flag_impu_work==1 & work_status==. & transition_work[_n-1]!=. & transition_work==0
    replace work_status=1 if flag_impu_work==1 & work_status==. & transition_work[_n-1]!=1 & transition_work[_n-1]==1
    replace work_status=0 if flag_impu_work==1 & work_status==. & transition_work[_n-1]!=1 & transition_work[_n-1]==0
    
                          }

    But some things unfortunately do not work / I do not understand.

    1. Since I set the imputation format to wide, it adds the variables _1_transition_work _2_transition_work ..... and only in _6_transition_work the actual value for transformation_work is implemented for t-1.
    Why is that? Should I rather mi set my data to flong or mlong?

    2. Then if I want to replace the missing information of transformation work in t-1 with the imputed value of _6_transition_work it does not work, because it sometimes said that this variable could not be find. And if I run the code with the replace command, _6_transition_work is not generated and just 5 imputation up to _5_transition_work were added to the dataset.


    So basically my question is, if there is an easy way to straight replace the imputed value into transition_work, so that then I can update the employment status in t?

    Thank you very much in advance!
Working...
X