Announcement

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

  • Generate a sequence of numbers with different tail number

    Hello,

    I am struggling with generating a sequence of numbers with different tail number. If there is anyone who can help me, I would appreciate a lot. Thank you in advance!

    I generally know how to generate a sequence number, but what I specifically want is the following:

    (what I have)
    zone tract
    1 52
    2 10
    3 66
    :
    :
    64 13

    (what I want to generate)
    zone# tract#
    1 1
    1 2
    : :
    : :
    1 52
    2 1
    2 2
    : :
    : :
    2 10
    3 1
    3 2
    : :
    : :
    3 66
    4 1
    : :
    : :
    64 1
    : :
    : :
    64 13


    Therefore, the data structure (#rows X #columns) of what I originally have is (64 X 2), but then the data structure of what I want to generate would be (1510 X 2). What would be the best way of generating the data on right hand side?

    Best,
    Hoyoung
    Last edited by Hoyoung Yoo; 30 Mar 2020, 17:38.

  • #2
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input byte(zone tract)
    1 52
    2 10
    3 66
    end
    
    expand tract
    by zone, sort: replace tract = _n

    In the future, when showing data examples, please use the -dataex- command to do so, as I have done here. If you are running version 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Thank you so much for your answer. It is very concise and accurate. Regarding -dataex-, that was my bad. I apologize that I didn't use it for asking a question. For future, I will keep that in mind.

      Comment

      Working...
      X