Announcement

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

  • Changing Values for IDs

    Dear all,

    I am using Stata 16.1. Unforunately the dataex command does not give me what I want. I have a rather simple question, but I do not how to code it. As you can see from the picture above, I would like that the values of pid_7 take the values of pid_6. For example, in the two cases I highlighted, I would wish that the values 2 of PID_7 change to 3 (pid_6) or the values 4 change to 5. Anyone has an idea of how to code that?

    Best,

    Simeon
    Attached Files

  • #2
    Unforunately the dataex command does not give me what I want.
    Try this:

    Code:
    dataex round parish_name hhid_6 pid_6 hhid_7 pid_7 pid_code
    or this to get into these two specific HHID:

    Code:
    dataex round parish_name hhid_6 pid_6 hhid_7 pid_7 pid_code if inlist(hhid_6, "H2810501", "H2810601")
    Also, your scheme may need a bit more explanation. For example, how would you resolve the first 4 cases? If the two 7's are changed to 8 (because pid_6 is 8), what would happen to cases 3 and 4 where pid_7 is already 8? In some way, I think it may make more sense to regroup them and reindex them, like this:

    Code:
    clear
    input str3 (x1 x2)
    A a1
    A a1
    A a2
    A a2
    A a2
    B b3
    B b3
    B b4
    B b5
    B b5
    end
    
    egen newvar = group(x1 x2)
    list, sep(0)
    Results:

    Code:
         +------------------+
         | x1   x2   newvar |
         |------------------|
      1. |  A   a1        1 |
      2. |  A   a1        1 |
      3. |  A   a2        2 |
      4. |  A   a2        2 |
      5. |  A   a2        2 |
      6. |  B   b3        3 |
      7. |  B   b3        3 |
      8. |  B   b4        4 |
      9. |  B   b5        5 |
     10. |  B   b5        5 |
         +------------------+
    Your problem can also be caused by something upstream. Without knowing how they were merged and how those pid were computed, it's hard to tell/help.
    Last edited by Ken Chui; 27 May 2022, 11:51.

    Comment

    Working...
    X