Announcement

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

  • Generating Variables from a long shaped data set

    Hi everybody,

    I want to analyse the effects of an divorce on well-being. As my variable for an divorce might be endogenous i wanted to use the employment status from last period as an IV for divorce (I know this is not currently the best IV to think of, but right now the method of how to apply IV in stata is more important to me).

    With employment status i mean: The Individual got unemployed due to a specific reason. In this case this would be due to dismissal or due to a plant closure.

    now my data looks like this ( i hope i used dataex in the right way)

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input long persnr byte partner long partnr byte(d2lifesat ue_reg artende emplst jobch)
     101 1    102  0 2 . 1 2
     101 1    102 -2 2 . 1 2
     101 1    102  0 2 . 1 2
     301 1    302 -1 2 2 1 4
     301 1    302 -3 2 . 1 2
     301 1    302 -1 2 2 1 4
     301 1    302  2 2 . 1 4
     301 1    302  0 2 2 1 4
     301 1    302 -7 2 . 3 4
     302 1    301 -1 2 . 1 2
     302 1    301 -4 2 . 1 2
     302 1    301 -1 2 . 1 2
     302 1    301 -9 2 . 2 2
     302 1    301 -1 2 . 1 4
     601 1 609102 -1 2 5 1 4
     601 1 609102 -1 2 . 1 2
     601 1 609102 -3 2 . 1 2
     601 1 609102  1 2 . 1 2
     601 1 609102  4 2 . 1 2
     601 1 609102  0 2 5 1 4
     601 1 609102 -3 2 . 1 4
     601 1 609102 -2 2 2 1 4
     601 1 609102  2 2 3 1 4
    1701 1   1704  0 2 . 1 2
    1701 1   1704 -1 2 . 1 2
    1701 1   1704  1 2 . 1 2
    1701 1   1704  2 2 . 1 2
    1701 1   1704 -1 2 . 1 2
    1701 1   1704 -1 2 . 1 2
    2101 1   2102 -2 2 . 1 2
    2101 1   2102 -2 2 . 1 2
    2101 1   2102  0 2 . 1 2
    2101 1   2102 -1 2 . 1 2
    2101 1   2102 -1 2 . 1 2
    2101 1   2102 -3 2 . 1 2
    2201 1   2202 -1 2 . 1 2
    2201 1   2202 -2 2 . 1 2
    2201 1   2202  3 2 . 1 2
    2201 1   2202  2 2 . 1 2
    2201 1   2202 -1 2 . 1 2
    2201 1   2202 -2 2 . 1 2
    2201 1   2202 -4 2 . 1 2
    2201 1   2202  4 2 . 1 2
    2202 1   2201 -1 2 2 4 4
    2202 1   2201 -5 2 . 2 2
    2202 1   2201 -1 2 5 2 4
    2702 1   2701  1 2 . 5 1
    2801 1   2802  0 2 . 1 2
    2801 1   2802  1 2 . 1 2
    2801 1   2802 -1 2 . 1 2
    2801 1   2802 -1 2 . 1 2
    2801 1   2802 -1 2 . 1 2
    2802 1   2801 -1 2 . 1 2
    2802 1   2801 -1 2 . 2 2
    2802 1   2801  0 2 . 2 2
    2802 1   2801  0 2 . 2 2
    2802 1   2801  1 2 . 1 2
    2802 1   2801  1 2 . 1 2
    2802 1 910603  1 2 . 5 1
    3001 1   3002  3 2 . 1 2
    3001 1   3002  0 2 . 1 2
    3001 1   3002  3 2 . 1 2
    3001 1   3002  5 2 . 2 2
    3001 1   3002  1 2 . 1 4
    3002 1   3001 -6 2 2 2 4
    3002 1   3001 -2 2 . 2 2
    3002 1   3001  5 2 2 2 4
    3002 1   3001  0 2 . 1 2
    3002 1   3001  0 2 . 1 2
    3002 1   3001  3 2 . 2 2
    3002 1   3001 -2 2 . 1 2
    3002 1   3001 -3 2 . 2 2
    3002 1   3001  2 2 . 2 2
    3301 1   3302 -1 2 . 1 2
    3302 1   3301  0 2 . 1 4
    3802 1   3801 -6 2 . 1 2
    3802 1   3801 -2 2 . 1 2
    3802 1   3801  5 2 . 1 2
    3802 1   3801  0 2 . 1 2
    4101 1   4102  0 2 . 1 2
    4101 1   4102  0 2 . 1 4
    4101 1   4102  0 2 . 1 2
    4101 1   4102  0 2 . 1 2
    4101 1   4102 -1 2 . 1 2
    4101 1   4102 -1 2 . 1 2
    4101 1   4102 -2 2 . 1 2
    4101 1   4102 -4 2 . 1 2
    4101 1   4102  1 2 . 1 2
    4101 1   4102  3 2 . 1 2
    4101 1   4102  0 2 . 1 2
    4102 1   4101 -1 2 . 1 4
    4102 1   4101 -1 2 . 1 2
    4102 1   4101  0 2 . 1 2
    4102 1   4101 -1 2 . 1 2
    4102 1   4101 -2 2 . 1 2
    4102 1   4101  0 2 . 1 2
    4102 1   4101  1 2 . 2 2
    4102 1   4101  1 2 . 2 4
    4102 1   4101  0 2 . 2 4
    4501 1   4502 -2 2 . 1 2
    end
    label values partner partner
    label def partner 1 "Partner", modify
    label values ue_reg bgp13
    label def bgp13 2 "[2] No", modify
    label values artende bgp28
    label def bgp28 2 "[2] Quit Job", modify
    label def bgp28 3 "[3] Dismissal", modify
    label def bgp28 5 "[5] Contract ended", modify
    label values emplst emplst16
    label def emplst16 1 "[1] Full Time", modify
    label def emplst16 2 "[2] Part Time", modify
    label def emplst16 3 "[3] Educational", modify
    label def emplst16 4 "[4] Minijob, modify
    label def emplst16 5 "[5] Not employed", modify
    label values jobch jobch16
    label def jobch16 1 "[1] Not employed", modify
    label def jobch16 2 "[2] Employed without changing employer", modify
    label def jobch16 4 "[4] Employed with changed employer", modify

    additonaly i have control variables for both the individual himself and his/her partner.


    My first question would be:

    1) The data is in long format. The variable for the divorce (sep2) and the instrument variables - i want to generate them myself using the available dataset. But i am not very sure of how to to that.


    Is this definition of a job loss in the previous period correct? (I only look at cases where the individual was either full or part time employed)


    Code:
        gen     ue_all=1 if ( l1.ue_reg==1) & (l2.emplst==1 | l2.emplst==2) 
        replace    ue_all=0 if l1.jobch==2 & (l2.emplst==1 | l2.emplst==2) & (l1.emplst==1 | l1.emplst==2)
    and dismissal would look like this

    Code:
        gen     ue_dismissal=1 if (l1.artende==2 & l1.ue_reg==1) & (l2.emplst==1 | l2.emplst==2) 
        replace    ue_dismissal=0 if l1.jobch==2 & (l2.emplst==1 | l2.emplst==2) & (l1.emplst==1 | l1.emplst==2)

    As far as divorce goes im am not so sure. As i can't time the moment of a partner change, i only want to look at those divorces which occur one period after the job loss. I want to generate a variable which represents the change in the partner number (partnr) .

    So in my opinion there are 2 possibilties. Either one can change the partner or dont have a partner at all

    it would look something like this

    Code:
    
    gen sep2=1 if             (l1.partner==1 & (partner==1) & partnr!=l1.partnr) | ///
                                (l1.partner==1 & (partner==0)
        
        replace sep2=0 if    l1.partner==1 & (partner==1)

    Would the definitions for those Varibales be correct?


    Would there be any differences in the final estimator when using wide shaped data instead of long shaped? (or can i just stick to the long shaped data)

    The Idea in general is to first run a OLS regression and then compare it with the the IV approach while using different instruments.


    Feel free to ask any additonal questions if i didn't provide you with sufficient information.



    Thank you

    Konstantin











  • #2
    Thank you for providing the code and data. You'll generally get a better response if you provide a shorter question. We don't need as many observations as you provide and you probably include stuff we don't need to know.

    A lot of your questions deal more with your data than Stata per se. How you define a job loss is a matter of the substance of your data. Likewise, what partner means is really a question about your data rather than Stata. The only thing I can do it to suggest you try it and then look at a bunch of observations to make sure it is doing what you want.

    By the way, you can usually make the dummy variables by just having the logical conditions:

    g sep2= (l1.partner==1 & (partner==1) & partnr!=l1.partnr) | (l1.partner==1 & (partner==0)

    I took the rhs from your statement but it won't run anyway - your parentheses are not balanced. I'd also suggest more parentheses to clarify the conditions. And, as a matter of personal preference, I use L in lags to make it look different than the number 1 or the operator |.

    Comment

    Working...
    X