Announcement

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

  • Failing to completely replace values accurately

    Please note I am using Stata 15.0, I can not use Datex as its available from 15.1. I can not download this function as the database is stored remotely, and not connected to the internet.

    Question: I have generated a new column, 'PreviouTrauma' to combine all the values in the 3 columns below. But the problem is, I am unable to replace completely the values for '0' and 'Null' for column indfor_failedfixation - the remaining 2 columns are not an issue.


    The three columns below are all STRING values

    SECTION 1
    indfor_prevtrauma indfor_trauma indfor_failedfixation
    0 0 0
    1 1 1
    NULL NULL NULL
    0 0 0
    1 1 1
    0 - 1260089,
    1 - 8002,
    Null - 252
    0 - 20212,
    1 - 39,
    NULL - 1268092
    0 - 20245,
    1 - 6,
    Null 1,268,092



    SECTION 2

    The values in bold are the total number of values with I used the code

    tab indfor_prevtrauma

    tab indfor_trauma

    tab indfor_failedfixation




    SECTION 3

    I would like to generate a column combining all three columns with the following values, with a generic column name as ‘PreviousTrauma’



    0 - No

    1 - Yes

    3- NULL




    Code used:



    generate PreviousTrauma = .

    replace PreviousTrauma =1 if indforprev_trauma == “1” | indfor_trauma == “1” | indfor_failedfixation == “1”

    replace PreviousTrauma = 0 if indforprev_trauma == “0” | indfor_trauma == “0”

    //I then checked the changes made which are equal to the values in the tab code used (SECTION 2) with results shown in the bold section (Section 1)//

    replace PreviousTrauma = 0 if indfor_failedfixation == “0”

    //Only 39 changes made which is inaccurate as there are 20245 values with ‘0’



    SECTION 4

    Another problem is when I start with the NULL section for one of the columns (see -Section 4.C)



    //A - all changes made accurately

    replace PreviousTrauma = 3 if indforprev_trauma == “NULL”


    //B - all changes made accurately

    replace PreviousTrauma = 3 if indfor_trauma == “NULL”


    //C -

    replace PreviousTrauma = 3 if indfor_failedfixation == “NULL”


    For C - no real changes made when I know from Section 2 and values in Section 1 that there are 1268092 values with ‘NULL’ in this column


    I then checked the changes made which are equal to the values in the tab code used (SECTION 2) with results shown in the bold section (Section 1)

    Question:
    To my mind, I can not see an issue with the code, but perhaps I stand to be corrected. Or is this an issue with the data?




  • #2
    When you specify -if indfor_failedfixation== "NULL"-, Stata is not going to do anything with observations where infor_failedfixation == "Null". String matching is case sensitive.

    It is not obvious, however, why you have some failures to match with "0". I suspect that the observations that you think should be matching do not actually contain "0" but instead contain something that looks like "0" to human eyes, but isn't, such as " 0" or "0 " or something like that.

    Since you do not provide example data in a manner that can be used for testing, it is not possible to provide more specific advice.

    Concerning -dataex-, it will run just fine with version 15.0. In fact, it can go all the way back to version 9! However, I understand that if you are forced to work on a computer that is isolated from the internet, you will not be able to install it, at least not in the usual way. But I would urge you to speak to your systems administrator and ask that person to install -dataex- for you. It can be done even without the internet by copying it to the appropriate directory from a copy on, say, a flash drive. It's really hard to make the most of Statalist without -dataex-.

    Comment


    • #3
      If Clyde's excellent advice is out of the question, then consider copying and pasting the results of

      Code:
      describe  indfor_* 
      list indfor_* in 1/20
      in between CODE delimiters summoned up with the # key in the Advanced Editor here.

      Such results will be much easier for experienced users to work with.

      Comment

      Working...
      X