Announcement

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

  • dropping a variable base of the condition of another variable

    Hi ,
    I want to drop the variable if the variable there is no value in the column variable or the result is 0 when sum of all values of the variable. I want to drop "sch_pri_no_bicyle" that has no value or as sum_sch_pri_no_bicyle is equal to Zero.
    drop sch_pri_no_bicyle if sum_sch_pri_no_bicyle==0
    But, it doesn't work.
    
    Please here is sample data set

    ----------------------- copy starting from the next line -----------------------
    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input int(sch_pri_no_bicyle sch_mid_no_bicyle sch_hig_no_bicyle) float(sum_sch_pri_no_bicyle sum_sch_mid_no_bicyle sum_sch_hig_no_bicyle)
    . 35 35 0 190 725
    . 20 20 0 190 725
    . 30 30 0 190 725
    . 20 20 0 190 725
    .  .  . 0 190 725
    end
    ------------------ copy up to and including the previous line ------------------

    

  • #2
    Your code doesn't work for me without a fix to remove characters not visible above. That said findname (Stata Journal) can do for you:


    Code:
    . findname, all(missing(@))
    sch_pri_no~e
    
    .
    . findname, all(@==0)
    sum_sch_pr~e
    and after each run of findname you can


    Code:
    drop `r(varlist)'

    . search findname, sj

    Search of official help files, FAQs, Examples, SJs, and STBs

    SJ-15-2 dm0048_3 . . . . . . . . . . . . . . . . Software update for findname
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q2/15 SJ 15(2):605--606
    updated to be able to find strL variables

    SJ-12-1 dm0048_2 . . . . . . . . . . . . . . . . Software update for findname
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q1/12 SJ 12(1):167
    correction for handling embedded double quote characters

    SJ-10-4 dm0048_1 . . . . . . . . . . . . . . . . Software update for findname
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q4/10 SJ 10(4):691
    update for not option

    SJ-10-2 dm0048 . . . . . . . . . . . . . . Speaking Stata: Finding variables
    (help findname if installed) . . . . . . . . . . . . . . . N. J. Cox
    Q2/10 SJ 10(2):281--296
    produces a list of variable names showing which variables
    have specific properties, such as being of string type, or
    having value labels attached, or having a date format

    (end of search)

    Note that I didn't take you literally. A variable with values 1 -1 will have sum zero but seems likely to be informative.

    Comment

    Working...
    X