count valid N

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

silaarts
Posts: 1
Joined: Fri Sep 13, 2013 8:29 am

count valid N

Postby silaarts » Fri Sep 13, 2013 8:41 am

I want to count 'a variabele'. That is, I want to count how many missing there are in one variabele.
Of course, this is easy by using 'frequencies variables age' (for exmaple).
However, I want a syntax that can say a smuch as 'if frequencies variables >99 then analysis....'.
Hence, I only want to conduct an analysis if the N of the sample (i.e. the frequences without the missings) is at least 100.

I think I should use lag or loop. However, I can not get SPSS to count for me in one variable and provide me the total of that variabele in, for example, another variabele.
If so, then I could use 'If (var1 >99) then regression...'.
statman
Administrator
Posts: 2734
Joined: Tue Jun 12, 2007 12:08 pm
Location: Florida, USA

Re: count valid N

Postby statman » Fri Sep 13, 2013 1:43 pm

If clear then can't do directly but might with a macro (can't help there) but look into the OMS function whereby you can run an analysis, e.g., FREQ and output to a dataset then read a data value from the dataset as a check to run another analysis on a different dataset
See the note below

NOTE: Please read the Posting Guidelines and always tell us your OS, the SPSS version and information about your study and data!

Statman
Statistical Services
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

Re: count valid N

Postby pythonforspss.org » Tue Sep 24, 2013 5:16 pm

You could do it without Python but that would be very clumsy. For a syntax demonstration of how to do it efficiently, see this tutorial: http://www.spss-tutorials.com/restrict- ... m-valid-n/.
Last edited by pythonforspss.org on Fri Nov 15, 2013 9:10 am, edited 2 times in total.
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: count valid N

Postby GerineL » Tue Oct 01, 2013 9:21 am

you can simply do this in 2-3 steps I think:


a) compute a new variable that holds 1 if a case is not missing (if vara > .01 or whatever is applicable in your situation)
b) using aggregate, create a sum score for that entire variable (e.g.: sum_var1)
c) use if (sum_var1 > 99) ..... etc.
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

Re: count valid N

Postby pythonforspss.org » Tue Oct 01, 2013 5:15 pm

@Gutnre: please provide us with a working syntax example of what you mean.
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: count valid N

Postby GerineL » Wed Oct 02, 2013 8:46 am

I thought it was pretty clear but ok.

Let's assume the variable that should have at least 99 non missing is called var1.
Easiest I can think of is:


recode var1 (sysmis = 99999).

if (var1 = 99999) temp1 = 1.
execute.

aggregate /outfile=*
mode=addvariables
/tempsum = sum(temp1).

delete variables temp1.


Then it depends on what analysis should follow, but now you have a variable that shows the number of non-missings in a variable.
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

Re: count valid N

Postby pythonforspss.org » Wed Oct 02, 2013 9:03 am

The OP was asking for a FREQUENCIES command that automatically excludes variables with less than N valid cases. How does your code accomplish that?
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: count valid N

Postby GerineL » Wed Oct 02, 2013 9:10 am

okay, then you add:

recode var1 (sysmis = 99999).

if (var1 = 99999) temp1 = 1.
execute.

aggregate /outfile=*
mode=addvariables
/tempsum = sum(temp1).

aggregate /outfile=*
mode=addvariables
/ntot = N(tempsum).

compute validn = ntot - tempsum.
execute.


Then you have a variable with the valid N.
I think that is what was asked for?
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

Re: count valid N

Postby pythonforspss.org » Wed Oct 02, 2013 9:20 am

I believe the OP was asking for a FREQUENCIES command that automatically excludes variables with less than N valid cases. So where are the frequencies tables?
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: count valid N

Postby GerineL » Wed Oct 02, 2013 9:31 am

Well let's let OP clarify what he/she wants exactly.
nyb10
Posts: 1
Joined: Thu Nov 07, 2013 8:16 pm

Re: count valid N

Postby nyb10 » Thu Nov 07, 2013 8:25 pm

I just joined the forum to find a solution to this exact problem: How to exclude cases with a count of less than N before running frequencies.

Alternatively, is it possible to select cases based on in-variable counts?
pythonforspss.org
Posts: 116
Joined: Sat Oct 06, 2012 6:21 am

Re: count valid N

Postby pythonforspss.org » Fri Nov 08, 2013 6:33 am

"How to exclude cases with a count of less than N before running frequencies?"

I already posted a solution for exactly that in this very same thread. If it's not to your liking, please clarify why.

I'm not sure what you mean with "in variable counts" but I'm confident we can fix that for you as well.
Kind regards,

Ruben Geert van den Berg
http://www.spss-tutorials.com

Who is online

Users browsing this forum: No registered users and 2 guests

cron