Announcement

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

  • reshape data and construct another data set

    I have a sample data with vars: id; location in certain year; sample weight. See attached (test.xlsx). I would like to get another data set which tracks the number of movements between locations by all possible location-pairs by year. The wanted data set also attached as xlsx. Hope this is clear from the attachment.
    Attached Files

  • #2
    Welcome to the Stata Forum/ Statalist,

    Please read the FAQ. There you’ll find information about posting a highly informative message as well as sharing data/command/output. Also, the reasons to avoid attached files.
    Best regards,

    Marcos

    Comment


    • #3
      Hello Marcos:

      Thanks for your information. I am new to stata. Here is my try to post my sample data and expected results.

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input byte id str2 location2000 str1(location2001 location2002) double weight
      1 "a" "a" "a" 1.11
      2 "a" "b" "a" 1.12
      3 "b" "b" "b"  .99
      4 "b" "a" "a" 1.01
      5 "b" "b" "a" 1.13
      end
      Expected result:

      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input int year str1(from to) double count byte E str102 notesnotneededforthedatat
      2001 "a" "a" 1.11 . "1.11 = 1*1.11, (count*sample_weight) i.e. from obs 1, moved from a to a (in year 2001 from year 200), "
      2001 "a" "b" 1.12 . "from obs2"                                                                                             
      2001 "b" "b" 2.12 . "from obs3 and 5:   1*0.99 + 1*1.13"                                                                    
      2001 "b" "a" 1.01 . "from obs4"                                                                                             
      2002 "a" "a" 2.12 . "from obs 1 and 4: 1*1.11 + 1*1.01"                                                                     
      2002 "a" "b"    0 . "no movement observed"                                                                                  
      2002 "b" "b"  .99 . "from obs 3"                                                                                            
      2002 "b" "a" 2.25 . "from obs2 and 5:   1*1.12 + 1*1.13"                                                                    
      end
      The last two columns are for explanation only, not needed for my result. I hope this is what you would like to see. Again, I am new here. Please let me know if there is anything i can improve.
      Thanks,
      Joe

      Comment

      Working...
      X