Announcement

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

  • Generate a unique observation identifier for panel data

    I have panel data and want to generate a unique identifier for each observation based on the participant's unique ID (numeric) and the wave of study (1-8). I want this to be replicable across multiple related datasets that will later be merged using the unique observation identifier (the participant IDs and wave variables are common across datasets).

    What functions of generate (or other commands) can I use to create this replicable, unique identifier? Ie, in an ideal world I'd just have something like 2103_03 to represent participant #2103 in wave 03.

  • #2
    I assume that wave of study is also numeric; try this
    Code:
    gen str newid = string(ID)+"_0"+string(wave)
    substitute your real variable names for "ID" and for "wave" in the above; also, I called the new variable "newid" but you can, obviously, choose your own name

    added: in the future, please follow the advice in the FAQ and use -dataex-

    Comment


    • #3
      Originally posted by Rich Goldstein View Post
      I assume that wave of study is also numeric; try this
      Code:
      gen str newid = string(ID)+"_0"+string(wave)
      substitute your real variable names for "ID" and for "wave" in the above; also, I called the new variable "newid" but you can, obviously, choose your own name

      added: in the future, please follow the advice in the FAQ and use -dataex-
      Hi Rich,

      I have a similar problem.... I have panel data.

      The panel unit is a variable 'mcspstate_nfhs5' representing a state of India and the time unit is year. The data represent yearly rate of a variable for years 2010 to 2020.

      I want to create a Unique Panel ID that represents a State for all the 'years' in a data set.

      [CODE]
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input int year float(mcspstate_nfhs5 my monthly_quality_rate yearly_quality_rate monthly_care_rate yearly_care_rate state phase mcspstate_nfhs4) byte _merge float(inter_state inter_period intervention)


      2015 1 660 72.97297 72.97297 58.82353 47.47082 1 5 . 1 1 0 0
      2015 1 661 71.42857 72.97297 45.23809 47.47082 1 5 . 1 1 0 0
      2015 1 662 73.68421 72.97297 52.63158 47.47082 1 5 . 1 1 0 0
      2015 1 663 81.81818 72.97297 36.363636 47.47082 1 5 . 1 1 0 0
      2015 1 664 42.85714 72.97297 57.14286 47.47082 1 5 . 1 1 0 0
      2015 1 665 87.5 72.97297 50 47.47082 1 5 . 1 1 0 0
      2015 1 666 71.42857 72.97297 57.14286 47.47082 1 5 . 1 1 0 0
      2015 1 667 81.81818 72.97297 33.333336 47.47082 1 5 . 1 1 0 0
      2015 1 668 80 72.97297 16 47.47082 1 5 . 1 1 0 0
      2015 1 669 69.565216 72.97297 60.86956 47.47082 1 5 . 1 1 0 0
      2015 1 670 84.61539 72.97297 46.15385 47.47082 1 5 . 1 1 0 0
      2015 1 671 57.14286 72.97297 52.38095 47.47082 1 5 . 1 1 0 0
      2016 1 672 70.96774 73.50746 32.258064 54.10448 1 5 . 1 1 1 1
      2016 1 673 71.69811 73.50746 52.83019 54.10448 1 5 . 1 1 1 1
      2016 1 674 63.63636 73.50746 54.54546 54.10448 1 5 . 1 1 1 1
      2016 1 675 91.66667 73.50746 50 54.10448 1 5 . 1 1 1 1
      2016 1 676 45.45455 73.50746 36.363636 54.10448 1 5 . 1 1 1 1
      2016 1 677 60 73.50746 50 54.10448 1 5 . 1 1 1 1
      2016 1 678 100 73.50746 63.63636 54.10448 1 5 . 1 1 1 1
      2016 1 679 77.27273 73.50746 59.09091 54.10448 1 5 . 1 1 1 1
      2016 1 680 53.33334 73.50746 80 54.10448 1 5 . 1 1 1 1
      2016 1 681 81.48148 73.50746 66.66667 54.10448 1 5 . 1 1 1 1
      2016 1 682 82.14286 73.50746 57.14286 54.10448 1 5 . 1 1 1 1
      2016 1 683 76.92308 73.50746 53.84616 54.10448 1 5 . 1 1 1 1
      2017 1 684 73.333336 78.88447 48.88889 53.35968 1 5 . 1 1 1 1
      2017 1 685 87.17949 78.88447 61.53846 53.35968 1 5 . 1 1 1 1
      2017 1 686 73.333336 78.88447 40 53.35968 1 5 . 1 1 1 1
      2017 1 687 78.94737 78.88447 52.63158 53.35968 1 5 . 1 1 1 1
      2017 1 688 57.14286 78.88447 57.14286 53.35968 1 5 . 1 1 1 1
      2017 1 689 88.88889 78.88447 55.55556 53.35968 1 5 . 1 1 1 1
      2017 1 690 76.92308 78.88447 64.28571 53.35968 1 5 . 1 1 1 1
      2017 1 691 81.25 78.88447 50 53.35968 1 5 . 1 1 1 1
      2017 1 692 91.30435 78.88447 52.17391 53.35968 1 5 . 1 1 1 1
      2017 1 693 78.57143 78.88447 50 53.35968 1 5 . 1 1 1 1
      2017 1 694 78.26087 78.88447 62.5 53.35968 1 5 . 1 1 1 1
      2017 1 695 76.190475 78.88447 42.85714 53.35968 1 5 . 1 1 1 1
      2018 1 696 58.33333 72.15687 61.11111 52.91829 1 5 . 1 1 1 1
      2018 1 697 73.68421 72.15687 65.789474 52.91829 1 5 . 1 1 1 1
      2018 1 698 68.965515 72.15687 34.482758 52.91829 1 5 . 1 1 1 1
      2018 1 699 83.33333 72.15687 50 52.91829 1 5 . 1 1 1 1
      2018 1 700 78.57143 72.15687 60 52.91829 1 5 . 1 1 1 1
      2018 1 701 87.5 72.15687 50 52.91829 1 5 . 1 1 1 1

      .


      Comment


      • #4
        I don't understand. Doesn't the variable mcspstate_nfhs5 already do that? What am I missing here?

        Comment

        Working...
        X