Announcement

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

  • Organising the data

    Hi
    I am new to this forum and my question may have been addressed before.
    I am working on a data where patients ( variable name = recordid) have received multiple treatments on different dates ( variable name = Dato).
    The column of recordid shows same recordids and infront of them multiple Dato in ascending order.
    I want to group similar recordids and their Datos with numbers as 1,2,3,4,.. in ascending order.
    the dataset is
    recordid Dato
    010462xxxx 22mar2021
    010462xxxx 19mar2021
    010462xxxx 26mar2021
    010462xxxx 24mar2021
    010462xxxx 31mar2021
    010462xxxx 29mar2021
    010548yyyy 18oct2021
    010548yyyy 27aug2021
    010548yyyy 27sep2021
    I would like to convert it to

    010462xxxx 1(22mar2021)
    2(19mar2021)
    3 (26mar2021)
    010548yyyy. 1(18oct2021)
    and further.
    Sorry for a very basic question.
    Thanks in Advance.

  • #2
    Your post has gone unanswered for about 6 hours now, which is a fairly long time on a weekday at this time of day. I can't speak for anybody else, but I do not understand what you want the final result to look like. The display you typed out doesn't resemble any kind of usable Stata data set.

    My best guess is that you just want a new variable that assigns a sequence number to the visits of each patient in chronological order. If so
    Code:
    by recordid (Dato), sort: gen int seq = _n
    It is also possible that you want the dates to be "side by side" rather than "vertical." In Stataspeak, that would mean converting the starting long data layout to wide. You can do that by adding the following command after the one shown above:
    Code:
    reshape wide Dato, i(recordid) j(seq)
    If neither of these is what you are looking for, you will need to give a better, clearer exposition of what you want. Do that by launching Stata and opening the Data Editor. In the Data Editor, mock up a small example of what the end result data set should look like. Then run -dataex-, and copy/paste the output -dataex- gives you into this Forum's editor as part of your post.

    If you are running version 18, 17, 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.

    Comment

    Working...
    X