Announcement

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

  • Copy the value of a variable from one wave to another

    Hello everyone,

    i would like to copy the value of my variables "spouse" "sub_h" and "age_int" from wave 6 to wave 5, so that they have the same value in both waves.
    An example for better understanding: The variable "age_int" is my age variable. For my regression I want no change in age over time and act as if they had the same age in both waves (but I need the age from wave 6).


    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input str12 mergeid float wave int age_int float(sub_h spouse)
    "AT-001492-02" 5 61 0 0
    "AT-001881-01" 6 85 0 0
    "AT-001881-02" 5 88 0 0
    "AT-001881-02" 6 90 0 0
    "AT-002136-01" 5 61 0 0
    "AT-002136-01" 6 63 0 0
    "AT-002136-03" 5 60 1 0
    "AT-002136-03" 6 62 1 0
    "AT-002180-02" 5 86 0 0
    "AT-002180-03" 5 72 0 1
    "AT-002525-01" 5 70 0 0
    "AT-002525-01" 6 72 0 0
    "AT-002525-02" 5 70 0 0
    "AT-002573-02" 5 71 1 0
    "AT-002965-02" 5 89 0 0
    "AT-002965-02" 6 91 0 0
    "AT-003194-01" 5 75 1 0
    "AT-003194-01" 6 77 1 1
    "AT-006788-02" 5 39 1 0
    "AT-006788-02" 6 41 1 0
    "AT-006788-04" 5 52 0 0
    "AT-006788-04" 6 54 1 0
    "AT-007170-01" 5 72 0 0
    "AT-007170-02" 5 69 1 0
    "AT-007854-02" 5 66 0 0
    "AT-008318-01" 5 71 0 0
    "AT-008318-01" 6 73 0 0
    "AT-008616-01" 5 60 0 1
    "AT-008616-01" 6 62 0 1
    "AT-008616-02" 5 62 0 1
    "AT-008616-02" 6 64 0 0
    "AT-008775-02" 5 70 0 0
    "AT-008912-01" 5 63 0 0
    "AT-009262-01" 5 57 0 0
    "AT-009262-02" 5 60 0 0
    "AT-009262-02" 6 63 0 1
    "AT-009376-01" 5 55 1 0
    "AT-009376-01" 6 57 0 0
    "AT-009376-04" 5 53 0 0
    "AT-009376-04" 6 55 1 0
    end
    label values age_int age
    label values sub_h sub_h_l
    label def sub_h_l 0 "gut, ausreichend oder schlecht", modify
    label def sub_h_l 1 "ausgezeichnet bis sehr gut", modify

    Thank you in advance!

    Best wishes
    Nanke

  • #2
    The wave 6 value of any numeric variable v is

    Code:
    egen v6 = max(cond(wave == 6, v, .)), by(mergeid)

    Comment


    • #3
      This worked perfectly, thank you so much.

      Comment

      Working...
      X