How to delete dummy value labels for a variable or variables

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

How to delete dummy value labels for a variable or variables

snehachidire
For a variable VAR1, we have 1-200 value labels.
In those only the applicable value labels are only 70 (randomly) means rest 130 (randomly) has no data in this perticular data set.
Is there any way to remove those dummy value labels (130) for that variable.
Solution may be for one variable or multiple variables also fine.

Thanks in advance,
Sneha
Reply | Threaded
Open this post in threaded view
|

Re: How to delete dummy value labels for a variable or variables

Art Kendall
Please clarify your situation.
How can 1 variable VAR1 have 1 to 200 value labels?
If your dictionary is for several datasets, what benefit is there to removing value labels?  
Except for DISPLAY the value labels will not appear in the output.
try the syntax snippet below.

data list list/ var1 (f3).
begin data
   11
   28
   30
end data.
value labels var1
   1 'a'
   11 'aa'
   28 'a word'
   30 'something'
   55 'why'
   99 'why not'.
frequencies variables = var1.
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: How to delete dummy value labels for a variable or variables

Jon Peck
GGRAPH and CTABLES will by default use value labels to determine categories to display, but this option can be turned off.  Most (all?) other procedures do not.  To get rid of value labels with no data requires a little Python programmability, which I can supply if this is really needed.  Please clarify

On Mon, Feb 29, 2016 at 7:46 AM, Art Kendall <[hidden email]> wrote:
Please clarify your situation.
How can 1 variable VAR1 have 1 *to* 200 value labels?
If your dictionary is for several datasets, what benefit is there to
removing value labels?
Except for DISPLAY the value labels will not appear in the output.
try the syntax snippet below.

data list list/ var1 (f3).
begin data
   11
   28
   30
end data.
value labels var1
   1 'a'
   11 'aa'
   28 'a word'
   30 'something'
   55 'why'
   99 'why not'.
frequencies variables = var1.



-----
Art Kendall
Social Research Consultants
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-delete-dummy-value-labels-for-a-variable-or-variables-tp5731633p5731635.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to delete dummy value labels for a variable or variables

Jon Peck
I see that the CODEBOOK command always displays all the labeled values whether or not you ask for any statistics.

On Mon, Feb 29, 2016 at 8:34 AM, Jon Peck <[hidden email]> wrote:
GGRAPH and CTABLES will by default use value labels to determine categories to display, but this option can be turned off.  Most (all?) other procedures do not.  To get rid of value labels with no data requires a little Python programmability, which I can supply if this is really needed.  Please clarify

On Mon, Feb 29, 2016 at 7:46 AM, Art Kendall <[hidden email]> wrote:
Please clarify your situation.
How can 1 variable VAR1 have 1 *to* 200 value labels?
If your dictionary is for several datasets, what benefit is there to
removing value labels?
Except for DISPLAY the value labels will not appear in the output.
try the syntax snippet below.

data list list/ var1 (f3).
begin data
   11
   28
   30
end data.
value labels var1
   1 'a'
   11 'aa'
   28 'a word'
   30 'something'
   55 'why'
   99 'why not'.
frequencies variables = var1.



-----
Art Kendall
Social Research Consultants
--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-delete-dummy-value-labels-for-a-variable-or-variables-tp5731633p5731635.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Jon K Peck
[hidden email]




--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: How to delete dummy value labels for a variable or variables

snehachidire
In reply to this post by Jon Peck
Thanks for the reply..

Our requirement: We are maintaining year wise data for products/brands from 2010-2014.
We have combined data set from 10 to 14 with cumilative value labels from 1 to 200.
Now we wants to split the data file to maintain year wise data.
We able to split the files with combined value labels only.But we want the data file with applicable value labels for each variable.

It would be helpful if you can provide a python program to remove the dummy value labels from the variables.
Reply | Threaded
Open this post in threaded view
|

Re: How to delete dummy value labels for a variable or variables

Jon Peck
Here is the code to run from the syntax window to do this.  Usage instructions are in the code.  If you need to limit the variables to process to a specified list, that could be added.  Copy it to a syntax window being careful to preserve the indentation.  I can't send it as an attachment either to you directly or via the X list.

* Encoding: UTF-8.
begin program.
# delete value labels that have no corresponding value in the data
# By default, all variables are processed.  Set omitscale=True in the last line
# to process only categorical variables.

import spss, spssaux, spssdata

def reducelabels(omitscale=False):
    """reduce value labels to only those corresponding to current values
    
    If omitscale is True, variables with a scale measurement level are not processed"""

    if omitscale:
        vardict = spssaux.VariableDict(variableLevel=["nominal", "ordinal", "unknown"])
    else:
        vardict = spssaux.VariableDict()
    allvalues = {}  # will track value occurrence for each variable
    thevars = sorted([(v.VariableIndex, v.VariableName) for v in vardict])
    thevars = [item[1] for item in thevars]
    for v in thevars:
        allvalues[v] = set()
        
    # find all values for selected variables
    curs = spssdata.Spssdata(thevars, names=False, convertUserMissing=False)
    for case in curs:
        for i, v in enumerate(thevars):
            if isinstance(case[i], basestring):
                allvalues[v].add(case[i].rstrip())
            else:
                allvalues[v].add(case[i])
    curs.CClose()

    # reduce value labels
    labelsdeleted = 0
    for va in thevars:
        vls = vardict[va].ValueLabelsTyped  # get current labels
        keep = set(vls.keys()).intersection(allvalues[va])
        labelsdeleted += len(vls) - len(keep)
        vardict[va].ValueLabels = dict([(k,v) for (k,v) in vls.items() if k in keep])
    print "***Labels deleted: %s" % labelsdeleted

reducelabels(omitscale=False)
end program.


On Mon, Feb 29, 2016 at 10:37 PM, snehachidire <[hidden email]> wrote:
Thanks for the reply..

Our requirement: We are maintaining year wise data for products/brands from
2010-2014.
We have combined data set from 10 to 14 with cumilative value labels from 1
to 200.
Now we wants to split the data file to maintain year wise data.
We able to split the files with combined value labels only.But we want the
data file with applicable value labels for each variable.

It would be helpful if you can provide a python program to remove the dummy
value labels from the variables.




--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/How-to-delete-dummy-value-labels-for-a-variable-or-variables-tp5731633p5731640.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD



--
Jon K Peck
[hidden email]

===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD