Announcement

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

  • Finding out fractional value from observations

    I am working on survey data where the variable "a01" stands for Household Identification Number (HID). In this database, fractional value means that the household has separated into two or three households over the course of time. Sample example using dataex :

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input double a01
       1
       2
       3
       4
       5
       6
       7
       8
       9
    10.1
    10.2
      11
      12
      13
      14
      15
    16.1
    16.2
    16.3
      17
      18
      19
      20
    end

    I have two questions.

    i) Can I separate the households which have fractional value? (i.e., I want to keep only 10.1,10.2,16.1,16.2,16.3)

    ii) Can I have only the first fractional value of the households which have separated? (i.e., I want to keep only 10.1 and 16.1)

  • #2
    Consider first

    Code:
    gen down = floor(a01)
    which rounds down to the nearest integer and so leaves integers as they are and removes the fractional part otherwise.

    The separated households are those with a fractional part and so can be identified as satisfying

    Code:
    a01 != down
    and so can be kept with

    Code:
    keep if a01 != down 
    Further the first such household can be kept with

    Code:
    bysort down (a01): keep if _N > 1 & _n == 1
    Last edited by Nick Cox; 10 Oct 2022, 02:51.

    Comment

    Working...
    X