Announcement

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

  • Issue with same observation but different values

    Hi,

    I am currently cleaning a dataset and would need help to complete it. There are duplicates in the dataset but they take on values. How can i delete the null for only D711 and D7233? please, need help.

    Grant Number Value
    D711 null
    D711 null
    D711 null
    D711 Yes
    D711 null
    D711 null
    D711 null
    D711 null
    D711 null
    D722 null
    D722 null
    D722 null
    D722 null
    D722 Yes
    D723 null
    D723 null
    D723 null
    D723 null
    D723 null
    D723 null

  • #2
    Code:
    drop if Value == "null" & inlist(GrantNumber, "D711", "D723")
    But what is the rationale for doing this? Why do you want to drop the null observations for those two grants, but not for D722? What is the larger issue you are trying to tackle in this phase of data cleaning? It looks as if you are headed towards a large number of ad hoc -drop if- statements that, individually at least, show no rhyme or reason. Probably there is some simpler, more generalized approach.

    In the future, when showing data examples, please use the -dataex- command to do so. If you are running version 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.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.

    Comment


    • #3
      Hi Clyde,

      Thanks for the reply. So, original dataset as over 100 observations. What I want to do it so remove the duplicates and retain a unique value for each observation. For the same observations with Yes and Null, I want to keep the Yes. For same observations with No and Null values, I want to keep the No. For observations with only null, I want to keep just 1 null. I need help on how to program this in stata.


      Grant Number Value
      D711 null
      D711 null
      D711 null
      D711 Yes
      D711 null
      D711 null
      D711 null
      D711 null
      D711 null
      D722 null
      D722 null
      D722 null
      D722 null
      D722 Yes
      D723 null
      D723 null
      D723 null
      D723 null
      D723 null
      D723 null

      Comment

      Working...
      X