Announcement

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

  • Numlist

    Hi is there anyone who has helpful information regarding the function 'numlist'

    I have check statahelp, stata journal and youtube and some previous posts posted on this forum

    I still have these questions:

    I understand that numlist refers to a range of numbers

    However, what I don't understand is how does stata know which range of numbers you are referring to?

    Say I have 4 columns in the midst of 25 columns of data with over 1 million rows, how does stata know which 4 columns I'm referring to if I need to use create a loop to cycle through the 4 columns to detect a particular code eg T76, T77, T89



    Basically I'm trying to do the following -
    Please note I posted the same dataset on here: https://www.statalist.org/forums/for...tring-function using a substring function, but I've decided to change course of attack.
    Instead I'll be picking out the pathologies I need and creating new columns rather than going through all the fields within my database.

    Example generated by -dataex-. For more info, type help dataex clear input float(Diagnosis1 Diagnosis2) str1 Diagnosis3 str4(Diagnosis4 Diagnosis5) 3 3 "3" "T345" "T345" 3 3 "4" "T88" "T77" 34 4 "4" "T76" "T88" 3 3 "4" "T76" "A76" 3 4 "3" "A89" "A89" 3 3 "4" "A09" "A09" 4 5 "6" "T89" "T89" end Lets say stroke = T76, T77, T89 I need to create a column with stroke = 1 Therefore gen stroke = 0 foreach num of numlist 3 4 { replace stroke = 1 if dg_'num >= T76 & dg_'num' <=T89


    Thanks

  • #2
    Your data example didn't emerge clearly. Please use CODE delimiters like this

    Code:
    like this

    Comment


    • #3
      I know this is against the rules, but currently on a PC without stata - which is the same as my previous post

      Here's the dataset

      * Example generated by -dataex-. For more info, type help dataex
      clear
      input float(Diagnosis1 Diagnosis2 Diagnosis3) str4(Diagnosis4 Diagnosis5)
      3 3 3 "T345" "T345"
      3 3 4 "T88" "T77"
      34 4 4 "T76" "T88"
      3 3 4 "T76" "A76"
      3 4 3 "A89" "A89"
      3 3 4 "A09" "A09"
      4 5 6 "T89" "T89"
      end
      [/CODE]
      ------------------ copy up to and including the previous line ------------------

      Listed 7 out of 7 observations
      Last edited by Martin Imelda Borg; 30 Aug 2022, 08:11.

      Comment

      Working...
      X