Announcement

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

  • Recode with if does not work

    Hi all,
    I have the following problem. I am trying to recode values of a variable conditioning on given vales of another variable as follows:

    recode dup_cc (0=-1) if pag_indici_all_2007!=.

    The recode command gives 0 changes.

    Any idea on why it does not work?
    Thank you in advance.

    Rezart

  • #2
    Rezart:
    works for me in the following toy-example:
    Code:
    . set obs 1
    number of observations (_N) was 0, now 1
    
    . g A=10
    
    . g B=0
    
    . recode B (0=-1) if A!=20
    (B: 1 changes made)
    
    . list
    
         +---------+
         |  A    B |
         |---------|
      1. | 10   -1 |
         +---------+
    
    .
    Check -dup_cc- original value.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Thank you Carlo,

      recode dup_cc (0=-1) if pag_indici_all_2007!=. still does not work to me.

      Maybe it depends on the fact that:

      1. the variable "pag_indici_all_2007" is created with the egen command in the following way? : bysort cc: egen pag_indici_all_2007=sum(tot_pagamenti_pop_2007)

      2. the recode is used after the duplication check command in the following way? : quietly by cc: gen dup_cc=cond(_N==1,0,_n)


      Thank you for your help.

      Rezart

      Comment


      • #4
        Neither of those previous commands are going to be remembered in any sense. Presumably "does not work for me" means that you got a message that 0 changes were made, just as this reproducible example shows:


        Code:
        . sysuse auto, clear
        (1978 Automobile Data)
        
        . recode mpg (50=60)
        (mpg: 0 changes made)
        .

        No values of 50 were changed to 60, because there are no values of 50.

        The evidence we need is the results of


        Code:
        count if dup_cc == 0 & pag_indici_all_2007 != . 
        
        tab dup_cc if pag_indici_all_2007 != .
        and my guess is that both commands will show no values of 0.

        Comment


        • #5
          Best would be if Original Poster provides a data sample using -dataex- and shows in which sense on this datasample the command "does not work."

          Comment


          • #6
            Dear Nick,

            your guess was right. For some strange reason I did not check whether the values were 0.

            Thank you,

            Rezart




            Comment

            Working...
            X