Announcement

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

  • Help manipulating data groups

    Hello,
    I am currently working with data about initial operations and subsequent readmissions which are recorded as separate observations. The index procedures and subsequent readmissions are identified by a variable "nod_visitlink" which tracks all observations about a particular patient. I have a variable "procname" which stores information regarding the type of operation that was received at index admission. I would like to add this data to all instances of patient admissions, i.e. subsequent readmissions which at this point only has missing values.


    gen index_procname = ""
    by nrd_visitlink, sort: gen pid = _n

    gen procnamedummy = 0
    replace procnamedummy = 1 if procname == "bpdds"
    replace procnamedummy = 2 if procname == "roux"
    replace procnamedummy = 3 if procname == "sleeve"

    forvalues i=1/ ?? {
    generate include = 1 if pid != `i' & procname != ""
    by(nrd_visitlink): gen work = procnamedummy
    replace index_procname = work if pid == `i'
    drop include work
    }

    This is what I have so far but does not seem to be working. Anybody have any experience with anything similar? Thank you.

  • #2
    ^^^^
    Click image for larger version

Name:	Screen Shot 2022-02-23 at 4.00.15 PM.png
Views:	1
Size:	483.0 KB
ID:	1651734

    Comment


    • #3
      I presume you have a variable that indicates the date or sequential order of each visit, in which case I believe the following does what I think you want:

      Code:
      bysort pid (VisitDate): replace procname = procname[1]
      For future postings, I'd encourage you to re-read the StataList FAQ (tab at top of screen) about the desirability of avoiding screenshots and using -dataex- to show example data.

      Comment

      Working...
      X