Announcement

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

  • Complete a database

    Good morning,

    I ask you for help because I need to complete a database.

    For that I have to change from this format:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(ID list x)
    1 1 10
    1 2 15
    1 4 10
    2 1 14
    2 5 15
    3 2 16
    3 3 12
    end

    To this one:

    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(ID list x)
    1 1 10
    1 2 15
    1 3  0
    1 4 10
    1 5  0
    2 1 14
    2 2  0
    2 3  0
    2 4  0
    2 5 15
    3 1  0
    3 2 16
    3 3 12
    3 4  1
    3 5  0
    end

    That is, for each ID, have a line for the 5 different "list", and if the "list" was not in the initial database then put 0 in the variable x
    Thanks a lot

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(ID list x)
    1 1 10
    1 2 15
    1 4 10
    2 1 14
    2 5 15
    3 2 16
    3 3 12
    end
    
    fillin ID list
    replace x=!x if _fillin
    Res.:

    Code:
    . l, sepby(ID)
    
         +--------------------------+
         | ID   list    x   _fillin |
         |--------------------------|
      1. |  1      1   10         0 |
      2. |  1      2   15         0 |
      3. |  1      3    0         1 |
      4. |  1      4   10         0 |
      5. |  1      5    0         1 |
         |--------------------------|
      6. |  2      1   14         0 |
      7. |  2      2    0         1 |
      8. |  2      3    0         1 |
      9. |  2      4    0         1 |
     10. |  2      5   15         0 |
         |--------------------------|
     11. |  3      1    0         1 |
     12. |  3      2   16         0 |
     13. |  3      3   12         0 |
     14. |  3      4    0         1 |
     15. |  3      5    0         1 |
         +--------------------------+

    Comment


    • #3
      Thanks !

      Comment

      Working...
      X