Hello,

I was working on a .ado file which was finsihed successfully. Unofrtunately there is a problem with missings I'm not getting rid of. I simplyfied the final result in this example, but solving it would really help me.

So this is the program, displaying the number of missing values at the end.

Code:
program test_miss
        version 16
        syntax varlist(max=2 numeric) [if] [in]
        
        local var1 = word("`varlist'",1)
        local var2 = word("`varlist'",2)
        
        marksample touse
        qui: count if `touse'
        local N = `r(N)'
        
        qui: tabulate `var1' `var2' if `touse'
        
        qui: d
        local miss = `r(N)' - `N'
        display "number of missings: N= " `miss'
end
My first test was:
Code:
****
** Test 1
****

input byte cat1 byte cat2 byte cat3
1 2 1
3 1 1
1 1 1
1 2 1
2 2 2
2 3 2
1 3 2
1 3 2
end

test_miss cat1 cat2                  // 0 Missings --> correct
test_miss cat1 cat2 if cat3 == 1     // 4 Missings --> not correct (correct = 0)
As you can see, using the "if" my missings are calculated wrong because cat3=2 data are taken into this calculation. I went on in some test with real missings:
Code:
****
** Test 2
****

* equal where the missing is in the 2-way table, it should count as a missing

clear
input byte cat1 byte cat2 byte cat3
1 . 1
. 1 1
1 1 1
1 2 1
2 2 2
2 . 2
1 3 2
. 3 2
end

test_miss cat1 cat2                 // 4 Missings --> correct
test_miss cat1 cat2 if cat3 == 1    // 6 Missings --> not correct (correct = 2)
That's why I tried to adapt my way of getting the correct missing by adding ", miss matcell(cell_miss)" as an option in my tabulate command, to get the matrix of missings in col and row (displayed alsway as last col and last row when using tabulate), but when using "if `touse' " and the option "miss", the command omits the "miss" option (I can see that in the cell_miss matrix) and only uses the if-part of the command.

I also tried other ways, but again when not using if, everything works fine, when using if, the missing value calculation is not correct.

So hope you have an idea.

Thanks
-Nick