Announcement

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

  • filling blank spaces for data in long format

    My data are repeated measures in long format as shown below. Since this is the same participant, How do I populate row 1 and 3 of the variable Age with the same value as row 2 since this is the same participant?

    id Time Age
    ID1 T1 .
    ID1 T2 23
    ID1 T3 .

  • #2
    Code:
    bys id (age): replace age = age[_n-1] if mi(age)

    Comment


    • #3
      I would expect age to change with time.... Are the times just days apart?

      Comment


      • #4
        Originally posted by Nick Cox View Post
        I would expect age to change with time.... Are the times just days apart?
        Fair point, time 1 and 2 are days apart, time 3 is 3 months later

        Comment


        • #5
          Originally posted by Øyvind Snilsberg View Post
          Code:
          bys id (age): replace age = age[_n-1] if mi(age)
          Thanks, but this results in 0 real changes

          Comment


          • #6
            hmm... perhaps,
            Code:
            bys id (age): replace age = age[1]
            also, consider using dataex to provide example dataset

            Comment


            • #7
              Is age numeric? May seem a stupid question, but I am puzzled why #2 does not work -- unless age is string.

              Comment


              • #8
                Originally posted by Øyvind Snilsberg View Post
                hmm... perhaps,
                Code:
                bys id (age): replace age = age[1]
                also, consider using dataex to provide example dataset
                This now works, many thanks

                Comment


                • #9
                  Originally posted by Nick Cox View Post
                  Is age numeric? May seem a stupid question, but I am puzzled why #2 does not work -- unless age is string.
                  I have a similar problem. I would like to populate the fac_groups_sd but using the command below, I get the error message "weights not allowed". Please help
                  bys id2 (fac_groups_sd): replace fac_groups_sd = fac_groups_sd[1]
                  * Example generated by -dataex-. To install: ssc install dataex
                  clear
                  input long id2 byte fac_groups_sd
                  1 1
                  1 .
                  1 .
                  1 .
                  1 .
                  1 .
                  2 1
                  2 .
                  2 .
                  2 .
                  2 .
                  2 .
                  3 .
                  4 1
                  4 .
                  4 .
                  4 .
                  4 .
                  4 .
                  4 .
                  5 2
                  5 .
                  5 .
                  5 .
                  5 .
                  6 4
                  6 .
                  6 .
                  6 .
                  6 .
                  6 .
                  7 4
                  7 .
                  7 .
                  7 .
                  7 .
                  7 .
                  8 1
                  8 .
                  8 .
                  8 .
                  8 .
                  8 .
                  9 1
                  9 .
                  10 1
                  10 .
                  10 .
                  10 .
                  10 .
                  10 .
                  10 .
                  11 1
                  11 .
                  11 .
                  11 .
                  11 .
                  11 .
                  11 .
                  12 1
                  13 1
                  14 3
                  14 .
                  14 .
                  14 .
                  14 .
                  14 .
                  15 1
                  15 .
                  15 .
                  15 .
                  15 .
                  15 .
                  16 1
                  16 .
                  16 .
                  16 .
                  16 .
                  16 .
                  17 2
                  17 .
                  17 .
                  17 .
                  17 .
                  17 .
                  18 2
                  18 .
                  18 .
                  18 .
                  18 .
                  18 .
                  19 2
                  19 .
                  19 .
                  19 .
                  19 .
                  19 .
                  20 5
                  20 .
                  20 .
                  end
                  label values id2 id2
                  label def id2 1 "MHGAP001", modify
                  label def id2 2 "MHGAP002", modify
                  label def id2 3 "MHGAP003", modify
                  label def id2 4 "MHGAP004", modify
                  label def id2 5 "MHGAP005", modify
                  label def id2 6 "MHGAP006", modify
                  label def id2 7 "MHGAP007", modify
                  label def id2 8 "MHGAP008", modify
                  label def id2 9 "MHGAP009", modify
                  label def id2 10 "MHGAP010", modify
                  label def id2 11 "MHGAP011", modify
                  label def id2 12 "MHGAP012", modify
                  label def id2 13 "MHGAP013", modify
                  label def id2 14 "MHGAP014", modify
                  label def id2 15 "MHGAP015", modify
                  label def id2 16 "MHGAP016", modify
                  label def id2 17 "MHGAP017", modify
                  label def id2 18 "MHGAP018", modify
                  label def id2 19 "MHGAP019", modify
                  label def id2 20 "MHGAP020", modify
                  [/CODE]

                  Comment


                  • #10
                    the code you show works for me on the data example provided:
                    Code:
                     bys id2 (fac_groups_sd): replace fac_groups_sd = fac_groups_sd[1]
                    (80 real changes made)
                    so, first try on your data example - if it works on the example but not on the full data then your example is not representative and you need look for where in your full data there are differences from what is in the example

                    Comment

                    Working...
                    X