Announcement

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

  • How to duplicate or repeat a set of values in a sequence in stata

    Hello,

    Kindly can anyone help me how I can duplicate values in sequence I want in Stata. I have data

    I have data in this form I want to convert in this form
    1 1
    2 1
    3 1
    4 1
    5 1
    2
    2
    2
    2
    2
    3
    3
    3
    3
    3 and so on


    The total values will be then 25. Your cooperation is of great value.
    Thanks in advance

  • #2
    Code:
    expand 5 
    sort whatever_it_is_called

    Comment


    • #3
      After applying code
      expand 5
      sort Origin
      i get these results

      I want it to be arranged in the order the way my original data is, not according to ascending or descending order. How I can do that
      Basic data After applying code in Stata But it Supposed to be like this
      year Origin year Origin year Origin
      2007 19946 2007 0 2007 19946
      2007 13054 2007 0 2007 19946
      2007 18119 2007 0 2007 19946
      2007 0 2007 0 2007 19946
      2007 1050 2007 0 2007 19946
      2007 1050 2007 13054
      2007 1050 2007 13054
      2007 1050 2007 13054
      2007 1050 2007 13054
      2007 1050 2007 13054
      2007 13054 2007 18119
      2007 13054 2007 18119
      2007 13054 2007 18119
      2007 13054 2007 18119
      2007 13054 2007 18119
      2007 18119 2007 0
      2007 18119 2007 0
      2007 18119 2007 0
      2007 18119 2007 0
      2007 18119 2007 0
      2007 19946 2007 1050
      2007 19946 2007 1050
      2007 19946 2007 1050
      2007 19946 2007 1050
      2007 199 2007 1050

      Comment


      • #4
        It's hard to see where this is going. If you want that and nothing else, then this is a way to do it.

        But why do you want that? For very small datasets, this might be a step towards manual entry of further data.

        If you want to merge with another dataset, then merge does this for you.

        Code:
        clear 
        input year    Origin        
        2007    19946        
        2007    13054        
        2007    18119        
        2007    0        
        2007    1050
        end 
        gen long order = _n 
        expand 5 
        sort year order 
        list year Origin, sepby(Origin)

        Comment


        • #5
          Wao it worked. Thank you so much.

          Comment


          • #6
            I have one more question:

            I have another data set in which I want to arrange values like below by repeating set of rows from (1 to 5) x 5 times


            Basic data I want in this form
            year Origin Year Origin
            2007 19946 2007 19946
            2007 13054 2007 13054
            2007 18119 2007 18119
            2007 0 2007 0
            2007 1050 2007 1050
            2007 19946
            2007 13054
            2007 18119
            2007 0
            2007 1050
            2007 19946
            2007 13054
            2007 18119
            2007 0
            2007 1050
            and so on

            Comment


            • #7
              Code:
              clear 
              input year    Origin        
              2007    19946        
              2007    13054        
              2007    18119        
              2007    0        
              2007    1050
              end 
              gen long order = _n 
              expand 5 
              sort order
              egen block = seq(), to(5)
              sort block order

              Comment


              • #8


                Thank you so much it worked.

                Comment


                • #9
                  Hello,

                  I have a time variable and total number of observation is suppose 83809. In that i first want to delete value at 28th position. Then I want to delete others at 289th position till the end. Kindly can you help me in that.
                  Last edited by Saher Malik; 15 Apr 2016, 03:00.

                  Comment


                  • #10
                    #9 should have started a new thread. The question doesn't match the title of the thread. Threads are defined by topics, not the people who start them.

                    There can be a need to do this.

                    You can go

                    Code:
                    drop in 28
                    but then what was observation 289 is now observation 288. If you ever forget it, you will get into messes.

                    I do use drop in interactively because (1) I know what I'm doing usually (2) I keep track of what was done using do files and log files (3) I am prepared to repeat myself if I mess up.

                    If you're a beginner, however, it is better to think in terms of drop if

                    That way, you specify why you are deleting data, which is crucial.
                    Last edited by Nick Cox; 15 Apr 2016, 03:58.

                    Comment

                    Working...
                    X