Announcement

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

  • Cleaning Data

    Hello everyone,

    sorry to request such trivial questions but i am a rookie in stata.

    I have a big longitudinal dataset and would love to clean my dataset and select the patients who received a certain strategy of treatment for the 3 possible lesions (cplx_strategy_of_pci___1, 2 and 3).
    Furthermore, each patients might have had several procedures (index, proc_2, proc_3) in which the treatment might have been used or not, again for each lesion (max 3 times)
    Each patient then had his/her follow-up where off course under "strategy" a missing value is showing.

    an example (not exactly the same of mine for sake of time)

    id--event_name--strategy--strategy_2--strategy_3
    1---index ----------1 ----------1 -------------.
    1---proc_2 --------0 ----------0 -------------.
    1---proc_3 --------. -----------. --------------.
    1---180d_fu -------. ----------. --------------.
    1---1y_fu ----------. -----------. --------------.
    1---2y_fu ----------. -----------. --------------.
    2---index ----------1 ----------0 -------------1
    2---1y_fu ----------. -----------. --------------.
    2---2y_fu ----------. -----------. --------------.
    3---index ----------0 ----------0 --------------.
    3---1y_fu ----------. -----------. --------------.
    3---2y_fu ----------. -----------. --------------.

    i tried to use this command:
    drop if cplx_strategy_of_pci___2 == 0 & cplx_strategy_of_pci_3___2 == 0 & cplx_strategy_of_pci_2___2 == 0

    this way i select only my strategy of interest which is fine for id 1 and 2 for example, but i drop only the "index" procedure for patient 3 and the follow ups remain and mess up my calculations.
    I tried to think of a solution but i am too noob for this.

    Could you please help me out?
    thank you very much in advance
    Last edited by Giacomo Cioffi; 06 Jun 2022, 07:42.

  • #2
    It would be easier to solve your problem with real example data. Use the dataex command and I'm sure it will be resolved.

    Comment


    • #3
      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str5 cplx_id str17 redcap_event_name byte(cplx_strategy_of_pci___2 cplx_strategy_of_pci_2___2 cplx_strategy_of_pci_3___2)
      "00001" "index_arm_1"       1 0 0
      "00002" "index_arm_1"       1 0 0
      "00002" "2_years_fu_arm_1"  . . .
      "00002" "event_1_arm_1"     . . .
      "00003" "index_arm_1"       1 0 0
      "00003" "2_years_fu_arm_1"  . . .
      "00003" "event_1_arm_1"     . . .
      "00004" "index_arm_1"       1 0 0
      "00004" "event_1_arm_1"     . . .
      "00005" "index_arm_1"       0 0 0
      "00005" "procedure_2_arm_1" 0 0 0
      "00005" "180_days_fu_arm_1" . . .
      "00005" "1_year_fu_arm_1"   . . .
      "00005" "2_years_fu_arm_1"  . . .
      "00006" "index_arm_1"       1 0 0
      "00006" "event_1_arm_1"     . . .
      "00007" "index_arm_1"       1 0 0
      "00007" "procedure_2_arm_1" 1 0 0
      "00007" "procedure_3_arm_1" 1 0 0
      "00007" "2_years_fu_arm_1"  . . .
      "00008" "index_arm_1"       1 0 0
      "00009" "index_arm_1"       1 0 0
      "00009" "procedure_2_arm_1" 0 0 0
      "00009" "1_year_fu_arm_1"   . . .
      "00009" "2_years_fu_arm_1"  . . .
      "00009" "event_1_arm_1"     . . .
      "00009" "event_2_arm_1"     . . .
      "00009" "event_3_arm_1"     . . .
      "00010" "index_arm_1"       1 1 0
      "00010" "event_1_arm_1"     . . .
      "00011" "index_arm_1"       1 0 0
      "00011" "2_years_fu_arm_1"  . . .
      "00011" "event_1_arm_1"     . . .
      "00012" "index_arm_1"       0 0 0
      "00012" "procedure_2_arm_1" 0 0 0
      "00012" "180_days_fu_arm_1" . . .
      "00012" "2_years_fu_arm_1"  . . .
      "00013" "index_arm_1"       1 0 0
      "00013" "2_years_fu_arm_1"  . . .
      "00013" "event_1_arm_1"     . . .
      "00014" "index_arm_1"       1 0 0
      "00014" "2_years_fu_arm_1"  . . .
      "00014" "event_1_arm_1"     . . .
      "00015" "index_arm_1"       1 0 0
      "00015" "procedure_2_arm_1" 0 0 0
      "00016" "index_arm_1"       1 1 0
      "00017" "index_arm_1"       0 0 0
      "00017" "procedure_2_arm_1" 0 0 0
      "00018" "index_arm_1"       1 0 0
      "00019" "index_arm_1"       0 0 0
      "00019" "event_1_arm_1"     . . .
      "00020" "index_arm_1"       1 0 0
      "00021" "index_arm_1"       0 0 0
      "00021" "procedure_2_arm_1" 0 0 0
      "00021" "2_years_fu_arm_1"  . . .
      "00021" "event_1_arm_1"     . . .
      "00022" "index_arm_1"       1 0 0
      "00022" "2_years_fu_arm_1"  . . .
      "00022" "event_1_arm_1"     . . .
      "00022" "event_2_arm_1"     . . .
      "00023" "index_arm_1"       0 0 0
      "00024" "index_arm_1"       0 0 0
      "00024" "procedure_2_arm_1" 0 0 0
      "00024" "procedure_3_arm_1" 0 0 0
      "00025" "index_arm_1"       0 0 0
      "00026" "index_arm_1"       1 0 0
      "00027" "index_arm_1"       1 0 0
      "00027" "event_1_arm_1"     . . .
      "00028" "index_arm_1"       1 0 0
      "00028" "2_years_fu_arm_1"  . . .
      "00029" "index_arm_1"       0 0 0
      "00030" "index_arm_1"       1 0 0
      "00030" "procedure_2_arm_1" 1 0 0
      "00031" "index_arm_1"       1 0 0
      "00032" "index_arm_1"       1 0 0
      "00032" "procedure_2_arm_1" 0 0 0
      "00032" "2_years_fu_arm_1"  . . .
      "00032" "event_1_arm_1"     . . .
      "00033" "index_arm_1"       0 0 0
      "00033" "procedure_2_arm_1" 0 0 0
      "00034" "index_arm_1"       0 0 0
      "00034" "procedure_2_arm_1" 0 0 0
      "00034" "procedure_3_arm_1" 1 0 0
      "00035" "index_arm_1"       0 0 0
      "00036" "index_arm_1"       0 1 0
      "00037" "index_arm_1"       0 0 0
      "00037" "procedure_2_arm_1" 1 0 0
      "00038" "index_arm_1"       0 1 0
      "00038" "event_1_arm_1"     . . .
      "00039" "index_arm_1"       1 0 0
      "00039" "event_1_arm_1"     . . .
      "00040" "index_arm_1"       0 0 0
      "00041" "index_arm_1"       1 0 0
      "00041" "event_1_arm_1"     . . .
      "00042" "index_arm_1"       1 1 0
      "00042" "procedure_2_arm_1" 0 0 0
      "00042" "event_1_arm_1"     . . .
      "00043" "index_arm_1"       1 0 0
      "00044" "index_arm_1"       0 0 0
      "00044" "procedure_2_arm_1" 0 0 0
      end
      label values cplx_strategy_of_pci___2 cplx_strategy_of_pci___2_
      label def cplx_strategy_of_pci___2_ 0 "Unchecked", modify
      label def cplx_strategy_of_pci___2_ 1 "Checked", modify
      label values cplx_strategy_of_pci_2___2 cplx_strategy_of_pci_2___2_
      label def cplx_strategy_of_pci_2___2_ 0 "Unchecked", modify
      label def cplx_strategy_of_pci_2___2_ 1 "Checked", modify
      label values cplx_strategy_of_pci_3___2 cplx_strategy_of_pci_3___2_
      label def cplx_strategy_of_pci_3___2_ 0 "Unchecked", modify
      for example patients number 00005 must be eliminated in toto but with my coding only the index and procedure row are deleted
      Last edited by Giacomo Cioffi; 06 Jun 2022, 07:57.

      Comment


      • #4
        Your question confuses me, but is this the result you hoped for?
        Code:
        * Example generated by -dataex-. For more info, type help dataex
        clear
        input str5 cplx_id str17 redcap_event_name byte(cplx_strategy_of_pci___2 cplx_strategy_of_pci_2___2 cplx_strategy_of_pci_3___2)
        "00001" "index_arm_1"       1 0 0
        "00002" "index_arm_1"       1 0 0
        "00002" "2_years_fu_arm_1"  . . .
        "00002" "event_1_arm_1"     . . .
        "00003" "index_arm_1"       1 0 0
        "00003" "2_years_fu_arm_1"  . . .
        "00003" "event_1_arm_1"     . . .
        "00004" "index_arm_1"       1 0 0
        "00004" "event_1_arm_1"     . . .
        "00005" "index_arm_1"       0 0 0
        "00005" "procedure_2_arm_1" 0 0 0
        "00005" "180_days_fu_arm_1" . . .
        "00005" "1_year_fu_arm_1"   . . .
        "00005" "2_years_fu_arm_1"  . . .
        "00006" "index_arm_1"       1 0 0
        "00006" "event_1_arm_1"     . . .
        "00007" "index_arm_1"       1 0 0
        "00007" "procedure_2_arm_1" 1 0 0
        "00007" "procedure_3_arm_1" 1 0 0
        "00007" "2_years_fu_arm_1"  . . .
        "00008" "index_arm_1"       1 0 0
        "00009" "index_arm_1"       1 0 0
        "00009" "procedure_2_arm_1" 0 0 0
        "00009" "1_year_fu_arm_1"   . . .
        "00009" "2_years_fu_arm_1"  . . .
        "00009" "event_1_arm_1"     . . .
        "00009" "event_2_arm_1"     . . .
        "00009" "event_3_arm_1"     . . .
        "00010" "index_arm_1"       1 1 0
        "00010" "event_1_arm_1"     . . .
        "00011" "index_arm_1"       1 0 0
        "00011" "2_years_fu_arm_1"  . . .
        "00011" "event_1_arm_1"     . . .
        "00012" "index_arm_1"       0 0 0
        "00012" "procedure_2_arm_1" 0 0 0
        "00012" "180_days_fu_arm_1" . . .
        "00012" "2_years_fu_arm_1"  . . .
        "00013" "index_arm_1"       1 0 0
        "00013" "2_years_fu_arm_1"  . . .
        "00013" "event_1_arm_1"     . . .
        "00014" "index_arm_1"       1 0 0
        "00014" "2_years_fu_arm_1"  . . .
        "00014" "event_1_arm_1"     . . .
        "00015" "index_arm_1"       1 0 0
        "00015" "procedure_2_arm_1" 0 0 0
        "00016" "index_arm_1"       1 1 0
        "00017" "index_arm_1"       0 0 0
        "00017" "procedure_2_arm_1" 0 0 0
        "00018" "index_arm_1"       1 0 0
        "00019" "index_arm_1"       0 0 0
        "00019" "event_1_arm_1"     . . .
        "00020" "index_arm_1"       1 0 0
        "00021" "index_arm_1"       0 0 0
        "00021" "procedure_2_arm_1" 0 0 0
        "00021" "2_years_fu_arm_1"  . . .
        "00021" "event_1_arm_1"     . . .
        "00022" "index_arm_1"       1 0 0
        "00022" "2_years_fu_arm_1"  . . .
        "00022" "event_1_arm_1"     . . .
        "00022" "event_2_arm_1"     . . .
        "00023" "index_arm_1"       0 0 0
        "00024" "index_arm_1"       0 0 0
        "00024" "procedure_2_arm_1" 0 0 0
        "00024" "procedure_3_arm_1" 0 0 0
        "00025" "index_arm_1"       0 0 0
        "00026" "index_arm_1"       1 0 0
        "00027" "index_arm_1"       1 0 0
        "00027" "event_1_arm_1"     . . .
        "00028" "index_arm_1"       1 0 0
        "00028" "2_years_fu_arm_1"  . . .
        "00029" "index_arm_1"       0 0 0
        "00030" "index_arm_1"       1 0 0
        "00030" "procedure_2_arm_1" 1 0 0
        "00031" "index_arm_1"       1 0 0
        "00032" "index_arm_1"       1 0 0
        "00032" "procedure_2_arm_1" 0 0 0
        "00032" "2_years_fu_arm_1"  . . .
        "00032" "event_1_arm_1"     . . .
        "00033" "index_arm_1"       0 0 0
        "00033" "procedure_2_arm_1" 0 0 0
        "00034" "index_arm_1"       0 0 0
        "00034" "procedure_2_arm_1" 0 0 0
        "00034" "procedure_3_arm_1" 1 0 0
        "00035" "index_arm_1"       0 0 0
        "00036" "index_arm_1"       0 1 0
        "00037" "index_arm_1"       0 0 0
        "00037" "procedure_2_arm_1" 1 0 0
        "00038" "index_arm_1"       0 1 0
        "00038" "event_1_arm_1"     . . .
        "00039" "index_arm_1"       1 0 0
        "00039" "event_1_arm_1"     . . .
        "00040" "index_arm_1"       0 0 0
        "00041" "index_arm_1"       1 0 0
        "00041" "event_1_arm_1"     . . .
        "00042" "index_arm_1"       1 1 0
        "00042" "procedure_2_arm_1" 0 0 0
        "00042" "event_1_arm_1"     . . .
        "00043" "index_arm_1"       1 0 0
        "00044" "index_arm_1"       0 0 0
        "00044" "procedure_2_arm_1" 0 0 0
        end
        label values cplx_strategy_of_pci___2 cplx_strategy_of_pci___2_
        label def cplx_strategy_of_pci___2_ 0 "Unchecked", modify
        label def cplx_strategy_of_pci___2_ 1 "Checked", modify
        label values cplx_strategy_of_pci_2___2 cplx_strategy_of_pci_2___2_
        label def cplx_strategy_of_pci_2___2_ 0 "Unchecked", modify
        label def cplx_strategy_of_pci_2___2_ 1 "Checked", modify
        label values cplx_strategy_of_pci_3___2 cplx_strategy_of_pci_3___2_
        label def cplx_strategy_of_pci_3___2_ 0 "Unchecked", modify
        
        cls
        
        
        qui levelsof cplx_id if cplx_strategy_of_pci___2 == 0 & ///
        cplx_strategy_of_pci_3___2 == 0 & ///
        cplx_strategy_of_pci_2___2 == 0, l(drops) sep(",")
        
        foreach x of loc drops {
            
            
            drop if cplx_id=="`x'"
        }

        Comment


        • #5
          Originally posted by Jared Greathouse View Post
          Your question confuses me, but is this the result you hoped for?
          Code:
          * Example generated by -dataex-. For more info, type help dataex
          clear
          input str5 cplx_id str17 redcap_event_name byte(cplx_strategy_of_pci___2 cplx_strategy_of_pci_2___2 cplx_strategy_of_pci_3___2)
          "00001" "index_arm_1" 1 0 0
          "00002" "index_arm_1" 1 0 0
          "00002" "2_years_fu_arm_1" . . .
          "00002" "event_1_arm_1" . . .
          "00003" "index_arm_1" 1 0 0
          "00003" "2_years_fu_arm_1" . . .
          "00003" "event_1_arm_1" . . .
          "00004" "index_arm_1" 1 0 0
          "00004" "event_1_arm_1" . . .
          "00005" "index_arm_1" 0 0 0
          "00005" "procedure_2_arm_1" 0 0 0
          "00005" "180_days_fu_arm_1" . . .
          "00005" "1_year_fu_arm_1" . . .
          "00005" "2_years_fu_arm_1" . . .
          "00006" "index_arm_1" 1 0 0
          "00006" "event_1_arm_1" . . .
          "00007" "index_arm_1" 1 0 0
          "00007" "procedure_2_arm_1" 1 0 0
          "00007" "procedure_3_arm_1" 1 0 0
          "00007" "2_years_fu_arm_1" . . .
          "00008" "index_arm_1" 1 0 0
          "00009" "index_arm_1" 1 0 0
          "00009" "procedure_2_arm_1" 0 0 0
          "00009" "1_year_fu_arm_1" . . .
          "00009" "2_years_fu_arm_1" . . .
          "00009" "event_1_arm_1" . . .
          "00009" "event_2_arm_1" . . .
          "00009" "event_3_arm_1" . . .
          "00010" "index_arm_1" 1 1 0
          "00010" "event_1_arm_1" . . .
          "00011" "index_arm_1" 1 0 0
          "00011" "2_years_fu_arm_1" . . .
          "00011" "event_1_arm_1" . . .
          "00012" "index_arm_1" 0 0 0
          "00012" "procedure_2_arm_1" 0 0 0
          "00012" "180_days_fu_arm_1" . . .
          "00012" "2_years_fu_arm_1" . . .
          "00013" "index_arm_1" 1 0 0
          "00013" "2_years_fu_arm_1" . . .
          "00013" "event_1_arm_1" . . .
          "00014" "index_arm_1" 1 0 0
          "00014" "2_years_fu_arm_1" . . .
          "00014" "event_1_arm_1" . . .
          "00015" "index_arm_1" 1 0 0
          "00015" "procedure_2_arm_1" 0 0 0
          "00016" "index_arm_1" 1 1 0
          "00017" "index_arm_1" 0 0 0
          "00017" "procedure_2_arm_1" 0 0 0
          "00018" "index_arm_1" 1 0 0
          "00019" "index_arm_1" 0 0 0
          "00019" "event_1_arm_1" . . .
          "00020" "index_arm_1" 1 0 0
          "00021" "index_arm_1" 0 0 0
          "00021" "procedure_2_arm_1" 0 0 0
          "00021" "2_years_fu_arm_1" . . .
          "00021" "event_1_arm_1" . . .
          "00022" "index_arm_1" 1 0 0
          "00022" "2_years_fu_arm_1" . . .
          "00022" "event_1_arm_1" . . .
          "00022" "event_2_arm_1" . . .
          "00023" "index_arm_1" 0 0 0
          "00024" "index_arm_1" 0 0 0
          "00024" "procedure_2_arm_1" 0 0 0
          "00024" "procedure_3_arm_1" 0 0 0
          "00025" "index_arm_1" 0 0 0
          "00026" "index_arm_1" 1 0 0
          "00027" "index_arm_1" 1 0 0
          "00027" "event_1_arm_1" . . .
          "00028" "index_arm_1" 1 0 0
          "00028" "2_years_fu_arm_1" . . .
          "00029" "index_arm_1" 0 0 0
          "00030" "index_arm_1" 1 0 0
          "00030" "procedure_2_arm_1" 1 0 0
          "00031" "index_arm_1" 1 0 0
          "00032" "index_arm_1" 1 0 0
          "00032" "procedure_2_arm_1" 0 0 0
          "00032" "2_years_fu_arm_1" . . .
          "00032" "event_1_arm_1" . . .
          "00033" "index_arm_1" 0 0 0
          "00033" "procedure_2_arm_1" 0 0 0
          "00034" "index_arm_1" 0 0 0
          "00034" "procedure_2_arm_1" 0 0 0
          "00034" "procedure_3_arm_1" 1 0 0
          "00035" "index_arm_1" 0 0 0
          "00036" "index_arm_1" 0 1 0
          "00037" "index_arm_1" 0 0 0
          "00037" "procedure_2_arm_1" 1 0 0
          "00038" "index_arm_1" 0 1 0
          "00038" "event_1_arm_1" . . .
          "00039" "index_arm_1" 1 0 0
          "00039" "event_1_arm_1" . . .
          "00040" "index_arm_1" 0 0 0
          "00041" "index_arm_1" 1 0 0
          "00041" "event_1_arm_1" . . .
          "00042" "index_arm_1" 1 1 0
          "00042" "procedure_2_arm_1" 0 0 0
          "00042" "event_1_arm_1" . . .
          "00043" "index_arm_1" 1 0 0
          "00044" "index_arm_1" 0 0 0
          "00044" "procedure_2_arm_1" 0 0 0
          end
          label values cplx_strategy_of_pci___2 cplx_strategy_of_pci___2_
          label def cplx_strategy_of_pci___2_ 0 "Unchecked", modify
          label def cplx_strategy_of_pci___2_ 1 "Checked", modify
          label values cplx_strategy_of_pci_2___2 cplx_strategy_of_pci_2___2_
          label def cplx_strategy_of_pci_2___2_ 0 "Unchecked", modify
          label def cplx_strategy_of_pci_2___2_ 1 "Checked", modify
          label values cplx_strategy_of_pci_3___2 cplx_strategy_of_pci_3___2_
          label def cplx_strategy_of_pci_3___2_ 0 "Unchecked", modify
          
          cls
          
          
          qui levelsof cplx_id if cplx_strategy_of_pci___2 == 0 & ///
          cplx_strategy_of_pci_3___2 == 0 & ///
          cplx_strategy_of_pci_2___2 == 0, l(drops) sep(",")
          
          foreach x of loc drops {
          
          
          drop if cplx_id=="`x'"
          }
          lets take patient 00005 for example.
          my problem is that this patient received no treatment I am interested in each of the lesions (0, 0, 0).
          I want to drop such patients in block. So if strategy is 0 in every three lesions then drop it, if even one lesion is treated with my strategy (1) then keep the patient in block (that is all patient-related, from index to follow up)

          hope it is clearer

          Comment


          • #6
            Did you run the code I posted here? Patient 00005 is gone using the code I've written.

            Comment


            • #7
              Originally posted by Jared Greathouse View Post
              Did you run the code I posted here? Patient 00005 is gone using the code I've written.
              didn't work...i still have lots of patients (like the 12, 24 etc etc) who didnt receive the treatment

              Comment


              • #8
                Originally posted by Jared Greathouse View Post
                Did you run the code I posted here? Patient 00005 is gone using the code I've written.
                it seems like it does the drop just one patient at a time, because if i repeat the whole command it removes another patient, but always one at the time.
                Shouldnt foreach cycle to all of the list in the command?

                Comment


                • #9
                  Click image for larger version

Name:	Schermata 2022-06-06 alle 22.59.15.png
Views:	1
Size:	155.5 KB
ID:	1668118



                  this is where it gets stuck but i don't understand what i should correct

                  Comment


                  • #10
                    got it...the comma was the problem, get rid of sep (",") in the qui levelsof command and solve the problem

                    Comment


                    • #11
                      Dear all, continuing on the saga of cleaning data, i came up another question. I guess cleaning data is really one of the most important thing.
                      Hope you can help me out
                      I'll attach the code under

                      Question is as follows:
                      I created a var (cplx_sdd) which is "same day discharge" yes/no based on the cplx_stay variable (Outpatient, Overnight/Day hospital, in-hospital).
                      Since it is a longitudinal database the value is only at the "index_arm_1" of the variable redcap_event_name.
                      This doesn't allow mie to then perform follow-up analysis of patient "sdd" yes/no since follow ups are under the redcap_event "180_days_fu_arm_1", "1_year_fu_arm_1", "2_years_fu_arm_1" etc, where under sdd there is a missing value off course.
                      Is there a way (foreach or something) to fill those missing values with the corresponding 1 or 0 for each patient?
                      for example for the patient 00002 SDD is 1 and I'd like to have that 1 also under the "2_years_fu_arm_1" and "event_1_arm_1", whereas patient 00005 needs to have 0 on each of his other redcap_event

                      Hope this makes sense.
                      I tried to use replace with foreach and levels but i'm too much of a rookie


                      thanks in advance for your help

                      Code:
                      * Example generated by -dataex-. For more info, type help dataex
                      clear
                      input str5 cplx_id str17 redcap_event_name byte cplx_stay float cplx_sdd
                      "00001" "index_arm_1"       1 1
                      "00002" "index_arm_1"       1 1
                      "00002" "2_years_fu_arm_1"  . .
                      "00002" "event_1_arm_1"     . .
                      "00003" "index_arm_1"       1 1
                      "00003" "2_years_fu_arm_1"  . .
                      "00003" "event_1_arm_1"     . .
                      "00004" "index_arm_1"       1 1
                      "00004" "event_1_arm_1"     . .
                      "00005" "index_arm_1"       3 0
                      "00005" "procedure_2_arm_1" . .
                      "00005" "180_days_fu_arm_1" . .
                      "00005" "1_year_fu_arm_1"   . .
                      "00005" "2_years_fu_arm_1"  . .
                      "00006" "index_arm_1"       1 1
                      "00006" "event_1_arm_1"     . .
                      "00007" "index_arm_1"       3 0
                      "00007" "procedure_2_arm_1" 2 0
                      "00007" "procedure_3_arm_1" . .
                      "00007" "2_years_fu_arm_1"  . .
                      "00008" "index_arm_1"       2 0
                      "00009" "index_arm_1"       2 0
                      "00009" "procedure_2_arm_1" 3 0
                      "00009" "1_year_fu_arm_1"   . .
                      "00009" "2_years_fu_arm_1"  . .
                      "00009" "event_1_arm_1"     . .
                      "00009" "event_2_arm_1"     . .
                      "00009" "event_3_arm_1"     . .
                      "00010" "index_arm_1"       3 0
                      "00010" "event_1_arm_1"     . .
                      "00011" "index_arm_1"       2 0
                      "00011" "2_years_fu_arm_1"  . .
                      "00011" "event_1_arm_1"     . .
                      "00012" "index_arm_1"       3 0
                      "00012" "procedure_2_arm_1" . .
                      "00012" "180_days_fu_arm_1" . .
                      "00012" "2_years_fu_arm_1"  . .
                      "00013" "index_arm_1"       1 1
                      "00013" "2_years_fu_arm_1"  . .
                      "00013" "event_1_arm_1"     . .
                      "00014" "index_arm_1"       1 1
                      "00014" "2_years_fu_arm_1"  . .
                      "00014" "event_1_arm_1"     . .
                      end
                      label values cplx_stay cplx_stay_
                      label def cplx_stay_ 1 "Outpatient", modify
                      label def cplx_stay_ 2 "Overnight/Day-Hospital", modify
                      label def cplx_stay_ 3 "In-Hospital", modify
                      Last edited by Giacomo Cioffi; 11 Jun 2022, 03:45.

                      Comment


                      • #12
                        anybody please?

                        Comment


                        • #13
                          I began reading at
                          Is there a way (foreach or something) to fill those missing values with the corresponding 1 or 0 for each patient?
                          Makes sense so far. You then write
                          for example for the patient 00002 SDD is 1 and I'd like to have that 1 also under the "2_years_fu_arm_1" and "event_1_arm_1", whereas patient 00005 needs to have 0 on each of his other redcap_event
                          I don't understand. Show me the exact code you used, don't tell me in words, show me the real code you've tried.


                          I don't understand the criteria here. Why does 002 need to be 0 and 005 need to be 1? Don't say anything about the broader details, tell me in logical terms why this needs to be true. For example, if I wanted to delineate people named Jared, I would do
                          Code:
                          g Jared= 1 if strpos(firstname, "Jared")
                          Here, the variable is 1 if the first name possesses (is) Jared. Logically, if the persons first name is Jared, then the variable MUST always and forever be 1.

                          So give me the same logical precision in your case, please. Tell me "0005 needs to be 0 because this variable is equal to this and this variable/time is greater than 0", for example. We need specificity here to answer a question like this one.

                          Comment


                          • #14
                            Ciao Jared

                            the code of the dataset is above. haven't tried anything yet because i cannot.
                            if you look at the dataset 2 post above you will see that each patient (cplx_id) has had an event (redcap_event_name) like index, then follow-up etc and some of them were outpatient, stayed overnight or in-hospital (cplx_stay).
                            I want to run analysis of patients who stayed overnight/in-hospital versus outpatients.
                            I thought i could solve it by simply creating a new dummy cplx_sdd (same day discharge) but i didn't realise that it fills up only the "rows" of the index_procedure. This happens because the cplx_stay was primarily in the index_procedure sheet in the database itself.
                            That been said, if i run a follow-up analysis i cannot differentiate overnight/in-hospital versus outpatients because the cplx_sdd has a missing value (see above) in every follow-up row

                            as example: patient 00002 (if you look the code 2 posts above) is cplx_sdd 1 but missing at "2_years_fu_arm_1" and at "event_1_arm_1"
                            whereas for example 00005 has cplx_sdd 0 and again missing (they should be 0 as well)

                            hope it's clearer


                            i tried using levelsof but doesn't work:


                            . levelsof cplx_id if cplx_sdd == 1, local(sdd)

                            foreach cplx_id of local sdd {
                            replace cplx_sdd=1 if cplx_sdd==.
                            }

                            (up until levelsof works fine because it puts in the local macro only the patient who were labeled as outpatients but then when i try to change those missing values with foreach it doesn't work)


                            thx a bunch
                            Last edited by Giacomo Cioffi; 12 Jun 2022, 00:41.

                            Comment


                            • #15
                              nobody can help me?jared?anyone please

                              Comment

                              Working...
                              X