Announcement

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

  • DATA Entry Question

    I have the data as below. Each subject has multiple rows of entries and only the first row of a particular subject has the information. Is there a STATA command that I can use to fill the same info of a particular subject in all rows (with same ID).



    clear
    input byte(ID Age) str1 Gender long INCOME
    1 34 "F" 10000
    1 . "" .
    1 . "" .
    2 65 "M" 25000
    2 . "" .
    3 24 "F" 8000
    3 . "" .
    3 . "" .
    3 . "" .
    3 . "" .
    3 . "" .
    3 . "" .
    4 69 "M" 190000
    5 17 "F" 45000
    5 . "" .
    6 79 "M" 56786
    6 . "" .
    6 . "" .
    6 . "" .
    6 . "" .
    7 10 "M" 140000
    7 . "" .
    7 . "" .
    7 . "" .
    8 49 "F" 240000
    8 . "" .
    8 . "" .
    9 56 "F" 230000
    9 . "" .
    9 . "" .
    10 90 "F" 600
    10 . "" .
    10 . "" .
    end

    I will really appreciate if someone can help me. My actual data has very large

  • #2
    The command is -carryforward- by David Kantor.

    Code:
    carryforward Age Gender INCOME, replace
    But since all the values are missing for these records where you are filling in the gaps, why not do:
    Code:
    sort ID, stable
    by ID: keep if _n==1
    To create a person level dataset without duplicates:

    Code:
         +----------------------------+
         | ID   Age   Gender   INCOME |
         |----------------------------|
      1. |  1    34        F    10000 |
      2. |  2    65        M    25000 |
      3. |  3    24        F     8000 |
      4. |  4    69        M   190000 |
      5. |  5    17        F    45000 |
         |----------------------------|
      6. |  6    79        M    56786 |
      7. |  7    10        M   140000 |
      8. |  8    49        F   240000 |
      9. |  9    56        F   230000 |
     10. | 10    90        F      600 |
         +----------------------------+

    Comment


    • #3
      https://www.stata.com/support/faqs/d...issing-values/ explains the principles.

      Comment

      Working...
      X