$casenum for households?

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

$casenum for households?

Christian Deindl
i try to be more precise this time.

i have a dataset with a personal id (id) and a household id (sampid)
that looks like this:

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.
list.

and i want to transform it into a dataset that loks like the following:

data list
/id (f2.0)   sampid (f13.0) houseid (f2.0).
begin data
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
101104200245000 6
end data.
list.

to put it simple: i just want to count the households. for that i assume
i need a "$casenum"-function for households. but i dont know how to do
it.

in stata it would like the following:

"sort sampid id
bys sampid: gen hhnr=_n if _n==1
replace hhnr = sum(hhnr)"

but i would prefer to do it in spss.


christian


Gene Maguin schrieb:
> Christian,
>
> For any of us to help you with this, you have to tell how (a step by step
> procedure) to get from the input to the output. For me at least, your
> description hasn't been good enough. If you don't get replies from others,
> they may be having the same problem. Please post your procedure to the list
> itself.
>
> Gene Maguin
Reply | Threaded
Open this post in threaded view
|

Re: $casenum for households?

Maguin, Eugene
Christian,

Exellant explanation. Thank you.

Compute houseid=1.
Do if (sampid eq lag(sampid)).
+   compute houseid=lag(houseid).
Else if (sampid ne lag(sampid)).
+   compute houseid=lag(houseid)+1.
End if.


Gene Maguin
Reply | Threaded
Open this post in threaded view
|

Re: $casenum for households?

Christian Deindl
gene,

your solution works perfect.

thanks a lot.

christian

Gene Maguin schrieb:

> Christian,
>
> Exellant explanation. Thank you.
>
> Compute houseid=1.
> Do if (sampid eq lag(sampid)).
> +   compute houseid=lag(houseid).
> Else if (sampid ne lag(sampid)).
> +   compute houseid=lag(houseid)+1.
> End if.
>
>
> Gene Maguin
>
>
>

--
__________________
Christian Deindl
Universität Zürich
Soziologisches Institut
Andreasstr. 15
CH - 8050 Zürich
Tel: 0041/(0)44/635 23 46

http://www.suz.unizh.ch/ages
Reply | Threaded
Open this post in threaded view
|

AW: $casenum for households?

la volta statistics
In reply to this post by Christian Deindl
Hi christian
Try the following code.
Hope that helps, Christian

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.

SOrt Cases by sampid.

Compute houseid = 1.
Compute #l = 1.
Loop #i = 1  to houseid.
+  Do if LAG(sampid) = sampid  .
+    Compute houseid = LAG(houseid,1) .
+  Else.
+    Compute  houseid = LAG(houseid,1) + #i.
+  End if.
End loop.
Exec.

*******************************
la volta statistics
Christian Schmidhauser, Dr.phil.II
Weinbergstrasse 108
Ch-8006 Zürich
Tel: +41 (043) 233 98 01
Fax: +41 (043) 233 98 02
email: mailto:[hidden email]
internet: http://www.lavolta.ch/


-----Ursprüngliche Nachricht-----
Von: SPSSX(r) Discussion [mailto:[hidden email]]Im Auftrag von
Christian Deindl
Gesendet: Freitag, 27. April 2007 12:05
An: [hidden email]
Betreff: $casenum for households?


i try to be more precise this time.

i have a dataset with a personal id (id) and a household id (sampid)
that looks like this:

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.
list.

and i want to transform it into a dataset that loks like the following:

data list
/id (f2.0)   sampid (f13.0) houseid (f2.0).
begin data
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
101104200245000 6
end data.
list.

to put it simple: i just want to count the households. for that i assume
i need a "$casenum"-function for households. but i dont know how to do
it.

in stata it would like the following:

"sort sampid id
bys sampid: gen hhnr=_n if _n==1
replace hhnr = sum(hhnr)"

but i would prefer to do it in spss.


christian


Gene Maguin schrieb:
> Christian,
>
> For any of us to help you with this, you have to tell how (a step by step
> procedure) to get from the input to the output. For me at least, your
> description hasn't been good enough. If you don't get replies from others,
> they may be having the same problem. Please post your procedure to the
list
> itself.
>
> Gene Maguin
Reply | Threaded
Open this post in threaded view
|

Re: $casenum for households?

George Emerson D'Umbra
In reply to this post by Christian Deindl
This is another way of doing that:

if sampid~=lag(sampid) or missing(lag(sampid)) houseid = houseid +1.
leave houseid.
exec.

I think it's worth mentioning this solution because of the LEAVE command. It
tells SPSS to not reinitialize houseid each time it prepares to read a new
case (so we don't need to compute it when it is the same sampid) and
initialize numeric variables with 0 (so we don't need to initialize
houseid).

Regards,
George


----- Original Message -----
From: "Christian Deindl" <[hidden email]>
To: <[hidden email]>
Sent: Friday, April 27, 2007 10:55 AM
Subject: Re: $casenum for households?


> gene,
>
> your solution works perfect.
>
> thanks a lot.
>
> christian
>
> Gene Maguin schrieb:
>> Christian,
>>
>> Exellant explanation. Thank you.
>>
>> Compute houseid=1.
>> Do if (sampid eq lag(sampid)).
>> +   compute houseid=lag(houseid).
>> Else if (sampid ne lag(sampid)).
>> +   compute houseid=lag(houseid)+1.
>> End if.
>>
>>
>> Gene Maguin
>>
>>
>>
>
> --
> __________________
> Christian Deindl
> Universität Zürich
> Soziologisches Institut
> Andreasstr. 15
> CH - 8050 Zürich
> Tel: 0041/(0)44/635 23 46
>
> http://www.suz.unizh.ch/ages
Reply | Threaded
Open this post in threaded view
|

Re: $casenum for households?

parisec
In reply to this post by Christian Deindl
Hi all,

I perused the archives in search of some syntax and lo and behold found post by Gene Maguin in 2007 that provides a solution to exactly what i want to do.  I used this syntax and it ran it without error, however it did not result in a "houseid", just a blank field.

The only difference in my file is that my "sampid" is a string field while this syntax has sampid as a numeric field. Could this be the problem and if so, is there a way to create the houseid if sampid is a string?

thanks a bunch.
Carol


Gene Maguin schrieb:

> Christian,
>
> Exellant explanation. Thank you.
>
> Compute houseid=1.
> Do if (sampid eq lag(sampid)).
> +   compute houseid=lag(houseid).
> Else if (sampid ne lag(sampid)).
> +   compute houseid=lag(houseid)+1.
> End if.
>
>
> Gene Maguin
>
>
>
i try to be more precise this time.

i have a dataset with a personal id (id) and a household id (sampid) that looks like this:

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.
list.

and i want to transform it into a dataset that loks like the following:

data list
/id (f2.0)   sampid (f13.0) houseid (f2.0).
begin data
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
101104200245000 6
end data.
list.

to put it simple: i just want to count the households. for that i assume i need a "$casenum"-function for households. but i dont know how to do it.

in stata it would like the following:

"sort sampid id
bys sampid: gen hhnr=_n if _n==1
replace hhnr = sum(hhnr)"

but i would prefer to do it in spss.


christian

--
__________________
Christian Deindl
Universität Zürich
Soziologisches Institut
Andreasstr. 15
CH - 8050 Zürich
Tel: 0041/(0)44/635 23 46

http://www.suz.unizh.ch/ages

=====================
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: $casenum for households?

Maguin, Eugene
Hi Carol,

Well! I never thought something I posted would come to 'something' me (not
quite sure of the right word there. Anyway, I think the thing that you may
not have done is put an execute after the 'end if', but, if so, your syntax
window ought to be showing a 'transformations pending' message. Could that
be true?

Gene


>>I perused the archives in search of some syntax and lo and behold found
post by Gene Maguin in 2007 that provides a solution to exactly what i want
to do.  I used this syntax and it ran it without error, however it did not
result in a "houseid", just a blank field.

The only difference in my file is that my "sampid" is a string field while
this syntax has sampid as a numeric field. Could this be the problem and if
so, is there a way to create the houseid if sampid is a string?

thanks a bunch.
Carol


Gene Maguin schrieb:

> Christian,
>
> Exellant explanation. Thank you.
>
> Compute houseid=1.
> Do if (sampid eq lag(sampid)).
> +   compute houseid=lag(houseid).
> Else if (sampid ne lag(sampid)).
> +   compute houseid=lag(houseid)+1.
> End if.
>
>
> Gene Maguin
>
>
>
i try to be more precise this time.

i have a dataset with a personal id (id) and a household id (sampid) that
looks like this:

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.
list.

and i want to transform it into a dataset that loks like the following:

data list
/id (f2.0)   sampid (f13.0) houseid (f2.0).
begin data
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
101104200245000 6
end data.
list.

to put it simple: i just want to count the households. for that i assume i
need a "$casenum"-function for households. but i dont know how to do it.

in stata it would like the following:

"sort sampid id
bys sampid: gen hhnr=_n if _n==1
replace hhnr = sum(hhnr)"

but i would prefer to do it in spss.


christian

--
__________________
Christian Deindl
Universität Zürich
Soziologisches Institut
Andreasstr. 15
CH - 8050 Zürich
Tel: 0041/(0)44/635 23 46

http://www.suz.unizh.ch/ages

=====================
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

=====================
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: $casenum for households?

parisec
Gene,

i think i've hijacked your syntax from other posts too and very much appreicate your contributions to the board.

I actually added the 'execute' statement to this thinking that would solve the problem but it didn't. my "SPSS processer is ready"

in addition, i tried creating houseid as a string but then it completely crunched. i know it's got to be something simple.

thanks
carol





-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Tuesday, April 07, 2009 11:51 AM
To: [hidden email]
Subject: Re: $casenum for households?

Hi Carol,

Well! I never thought something I posted would come to 'something' me (not quite sure of the right word there. Anyway, I think the thing that you may not have done is put an execute after the 'end if', but, if so, your syntax window ought to be showing a 'transformations pending' message. Could that be true?

Gene


>>I perused the archives in search of some syntax and lo and behold
>>found
post by Gene Maguin in 2007 that provides a solution to exactly what i want to do.  I used this syntax and it ran it without error, however it did not result in a "houseid", just a blank field.

The only difference in my file is that my "sampid" is a string field while this syntax has sampid as a numeric field. Could this be the problem and if so, is there a way to create the houseid if sampid is a string?

thanks a bunch.
Carol


Gene Maguin schrieb:

> Christian,
>
> Exellant explanation. Thank you.
>
> Compute houseid=1.
> Do if (sampid eq lag(sampid)).
> +   compute houseid=lag(houseid).
> Else if (sampid ne lag(sampid)).
> +   compute houseid=lag(houseid)+1.
> End if.
>
>
> Gene Maguin
>
>
>
i try to be more precise this time.

i have a dataset with a personal id (id) and a household id (sampid) that looks like this:

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.
list.

and i want to transform it into a dataset that loks like the following:

data list
/id (f2.0)   sampid (f13.0) houseid (f2.0).
begin data
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
101104200245000 6
end data.
list.

to put it simple: i just want to count the households. for that i assume i need a "$casenum"-function for households. but i dont know how to do it.

in stata it would like the following:

"sort sampid id
bys sampid: gen hhnr=_n if _n==1
replace hhnr = sum(hhnr)"

but i would prefer to do it in spss.


christian

--
__________________
Christian Deindl
Universität Zürich
Soziologisches Institut
Andreasstr. 15
CH - 8050 Zürich
Tel: 0041/(0)44/635 23 46

http://www.suz.unizh.ch/ages

=====================
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

=====================
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

=====================
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: $casenum for households?

Melissa Ives
You may need to put the Execute after the compute houseid=1.
I have seen times when you actually do need an Execute mid stream in order for one calculation to actually be completed prior to running the next.
This seems to be a similar case.

If Houseid is not initialized to 1, then it would end up blank.
Melissa

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Parise, Carol A.
Sent: Tuesday, April 07, 2009 2:02 PM
To: [hidden email]
Subject: Re: [SPSSX-L] $casenum for households?

Gene,

i think i've hijacked your syntax from other posts too and very much appreicate your contributions to the board.

I actually added the 'execute' statement to this thinking that would solve the problem but it didn't. my "SPSS processer is ready"

in addition, i tried creating houseid as a string but then it completely crunched. i know it's got to be something simple.

thanks
carol





-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Tuesday, April 07, 2009 11:51 AM
To: [hidden email]
Subject: Re: $casenum for households?

Hi Carol,

Well! I never thought something I posted would come to 'something' me (not quite sure of the right word there. Anyway, I think the thing that you may not have done is put an execute after the 'end if', but, if so, your syntax window ought to be showing a 'transformations pending' message. Could that be true?

Gene


>>I perused the archives in search of some syntax and lo and behold
>>found
post by Gene Maguin in 2007 that provides a solution to exactly what i want to do.  I used this syntax and it ran it without error, however it did not result in a "houseid", just a blank field.

The only difference in my file is that my "sampid" is a string field while this syntax has sampid as a numeric field. Could this be the problem and if so, is there a way to create the houseid if sampid is a string?

thanks a bunch.
Carol


Gene Maguin schrieb:

> Christian,
>
> Exellant explanation. Thank you.
>
> Compute houseid=1.
> Do if (sampid eq lag(sampid)).
> +   compute houseid=lag(houseid).
> Else if (sampid ne lag(sampid)).
> +   compute houseid=lag(houseid)+1.
> End if.
>
>
> Gene Maguin
>
>
>
i try to be more precise this time.

i have a dataset with a personal id (id) and a household id (sampid) that looks like this:

data list
/id (f2.0)   sampid (f13.0).
begin data
1 1104200032700
2 1104200032700
3 1104200057500
4 1104200057500
5 1104200181600
6 1104200181600
7 1104200213200
8 1104200235500
9 1104200235500
101104200245000
end data.
list.

and i want to transform it into a dataset that loks like the following:

data list
/id (f2.0)   sampid (f13.0) houseid (f2.0).
begin data
1 1104200032700 1
2 1104200032700 1
3 1104200057500 2
4 1104200057500 2
5 1104200181600 3
6 1104200181600 3
7 1104200213200 4
8 1104200235500 5
9 1104200235500 5
101104200245000 6
end data.
list.

to put it simple: i just want to count the households. for that i assume i need a "$casenum"-function for households. but i dont know how to do it.

in stata it would like the following:

"sort sampid id
bys sampid: gen hhnr=_n if _n==1
replace hhnr = sum(hhnr)"

but i would prefer to do it in spss.


christian

--
__________________
Christian Deindl
Universität Zürich
Soziologisches Institut
Andreasstr. 15
CH - 8050 Zürich
Tel: 0041/(0)44/635 23 46

http://www.suz.unizh.ch/ages

=====================
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

=====================
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

=====================
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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

=====================
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: $casenum for households?

Christian Deindl
In reply to this post by parisec
the original "sampid" is also a string.

but you can try the syntax below with does the same

if sampid~=lag(sampid) or missing(lag(sampid)) houseid = houseid +1.
leave houseid.
exec.


christian

On Tue, 7 Apr 2009 12:01:33 -0700
  "Parise, Carol A." <[hidden email]> wrote:

> Gene,
>
> i think i've hijacked your syntax from other posts too and very much
>appreicate your contributions to the board.
>
> I actually added the 'execute' statement to this thinking that would solve
>the problem but it didn't. my "SPSS processer is ready"
>
> in addition, i tried creating houseid as a string but then it completely
>crunched. i know it's got to be something simple.
>
> thanks
> carol
>
>
>
>
>
> -----Original Message-----
>From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
>Gene Maguin
> Sent: Tuesday, April 07, 2009 11:51 AM
> To: [hidden email]
> Subject: Re: $casenum for households?
>
> Hi Carol,
>
> Well! I never thought something I posted would come to 'something' me (not
>quite sure of the right word there. Anyway, I think the thing that you may
>not have done is put an execute after the 'end if', but, if so, your syntax
>window ought to be showing a 'transformations pending' message. Could that
>be true?
>
> Gene
>
>
>>>I perused the archives in search of some syntax and lo and behold
>>>found
> post by Gene Maguin in 2007 that provides a solution to exactly what i
>want to do.  I used this syntax and it ran it without error, however it did
>not result in a "houseid", just a blank field.
>
> The only difference in my file is that my "sampid" is a string field while
>this syntax has sampid as a numeric field. Could this be the problem and if
>so, is there a way to create the houseid if sampid is a string?
>
> thanks a bunch.
> Carol
>
>
> Gene Maguin schrieb:
>> Christian,
>>
>> Exellant explanation. Thank you.
>>
>> Compute houseid=1.
>> Do if (sampid eq lag(sampid)).
>> +   compute houseid=lag(houseid).
>> Else if (sampid ne lag(sampid)).
>> +   compute houseid=lag(houseid)+1.
>> End if.
>>
>>
>> Gene Maguin
>>
>>
>>
> i try to be more precise this time.
>
> i have a dataset with a personal id (id) and a household id (sampid) that
>looks like this:
>
> data list
> /id (f2.0)   sampid (f13.0).
> begin data
> 1 1104200032700
> 2 1104200032700
> 3 1104200057500
> 4 1104200057500
> 5 1104200181600
> 6 1104200181600
> 7 1104200213200
> 8 1104200235500
> 9 1104200235500
> 101104200245000
> end data.
> list.
>
> and i want to transform it into a dataset that loks like the following:
>
> data list
> /id (f2.0)   sampid (f13.0) houseid (f2.0).
> begin data
> 1 1104200032700 1
> 2 1104200032700 1
> 3 1104200057500 2
> 4 1104200057500 2
> 5 1104200181600 3
> 6 1104200181600 3
> 7 1104200213200 4
> 8 1104200235500 5
> 9 1104200235500 5
> 101104200245000 6
> end data.
> list.
>
> to put it simple: i just want to count the households. for that i assume i
>need a "$casenum"-function for households. but i dont know how to do it.
>
> in stata it would like the following:
>
> "sort sampid id
> bys sampid: gen hhnr=_n if _n==1
> replace hhnr = sum(hhnr)"
>
> but i would prefer to do it in spss.
>
>
> christian
>
> --
> __________________
> Christian Deindl
> Universität Zürich
> Soziologisches Institut
> Andreasstr. 15
> CH - 8050 Zürich
> Tel: 0041/(0)44/635 23 46
>
> http://www.suz.unizh.ch/ages
>
> =====================
> 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
>
> =====================
> 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
>
> =====================
> 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

__________________
Christian Deindl
Universität Zürich
Soziologisches Institut
Andreasstr. 15
CH - 8050 Zürich
Tel: 044/635 23 46

=====================
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: $casenum for households?

Richard Ristow
In reply to this post by Maguin, Eugene
At 09:49 AM 4/27/2007, Gene Maguin wrote:

>Compute houseid=1.
>Do if (sampid eq lag(sampid)).
>+   compute houseid=lag(houseid).
>Else if (sampid ne lag(sampid)).
>+   compute houseid=lag(houseid)+1.
>End if.

Interesting. At first glance, it looks like it won't work, because it
appears that one clause of the DO IF construct is always executed;
'houseid' is always computed from its LAG; so it starts as missing,
and stays that way.

You're taking advantage of a notorious quirk in SPSS: if a test in a
DO IF or ELSE IF evaluates as 'missing', that clause AND ALL
SUBSEQUENT CLAUSES, are skipped, with no notice. Ugh.

Two things: First, that won't work if 'sampid' is a string, because
in the first case lag(sampid) is an empty string, which isn't a
missing value. Second, there are drawbacks to relying on such an
obscure quirk, one which probably shouldn't be there in the first place.

Easy to fix, though fix not tested:

Do if    $CASENUM EQ 1.
+   Compute houseid=1.
Else if  (sampid eq lag(sampid)).
+   compute houseid=lag(houseid).
Else if (sampid ne lag(sampid)).
+   compute houseid=lag(houseid)+1.
End if.

=====================
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: $casenum for households?

Maguin, Eugene
Richard,

I'm curious about your comment about the 'quirk'. Like you, I've noticed
that there's times when the code I offered works and times when it doesn't.
I had an incident a few days ago and I fixed it by doing what you
suggested--explicitly testing for $casenum=1. There's a structure that makes
sense to the failures but I've never thought too hard about it because it
doesn't come up very often, I check my work, and I can fix up what doesn't
work. That said, I'm curious how you'd modify spss' operation to account, in
whatever sense you care to use the word, for the quirk. You've pointed
things like this out before and I've benefitted from your comments. If you'd
care to offer a comment, I'd be interested to hear it.

Gene Maguin

=====================
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: $casenum for households?

parisec
In reply to this post by Richard Ristow
I ran this and it did the trick.

Very intresting.

Thanks a bunch to you both.

Carol


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Richard Ristow
Sent: Tuesday, April 07, 2009 1:15 PM
To: [hidden email]
Subject: Re: $casenum for households?

At 09:49 AM 4/27/2007, Gene Maguin wrote:

>Compute houseid=1.
>Do if (sampid eq lag(sampid)).
>+   compute houseid=lag(houseid).
>Else if (sampid ne lag(sampid)).
>+   compute houseid=lag(houseid)+1.
>End if.

Interesting. At first glance, it looks like it won't work, because it
appears that one clause of the DO IF construct is always executed;
'houseid' is always computed from its LAG; so it starts as missing, and
stays that way.

You're taking advantage of a notorious quirk in SPSS: if a test in a DO
IF or ELSE IF evaluates as 'missing', that clause AND ALL SUBSEQUENT
CLAUSES, are skipped, with no notice. Ugh.

Two things: First, that won't work if 'sampid' is a string, because in
the first case lag(sampid) is an empty string, which isn't a missing
value. Second, there are drawbacks to relying on such an obscure quirk,
one which probably shouldn't be there in the first place.

Easy to fix, though fix not tested:

Do if    $CASENUM EQ 1.
+   Compute houseid=1.
Else if  (sampid eq lag(sampid)).
+   compute houseid=lag(houseid).
Else if (sampid ne lag(sampid)).
+   compute houseid=lag(houseid)+1.
End if.

=====================
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

=====================
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
|

does spss require ascii characters

mpirritano
In reply to this post by Christian Deindl
I am trying to read in a dataset that is encoded as Unicode utf-16. I've
gotten help from the folks on the python list to create some code to
translate it into ascii. But I get the following error:

Traceback (most recent call last):
  File "C:\Projects\unicode_convert.py", line 8, in <module>
    outp.write(outLine.strip()+'\n')
UnicodeEncodeError: 'ascii' codec can't encode characters in position
640-641: ordinal not in range(128)


My question is, is there a way to read non-ascii characters?

I've tried setting the character encoding for data and syntax as Unicode
and then opening my data, which is in the form of a text file, but I
cannot read the file.

Do I have to convert this file first? That's what I've done in the past,
but this time I'm getting this error and so am looking for a possible
workaround.

Thanks
matt



Matthew Pirritano, Ph.D.
Research Analyst IV
Medical Services Initiative (MSI)
Orange County Health Care Agency
(714) 568-5648

=====================
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: does spss require ascii characters

Peck, Jon
Are you just trying to read a text into SPSS?  Are all the characters plain 7-bit ascii?  Does the file have a BOM (byte order mark) at the start?

The DATA LIST command can read utf-16.  You can specify ENCODING=UTF16, and it should lap it right up.  Best if SPSS is running in Unicode mode for this.

As far as the Python code below goes, your translation code is probably wrong.  You need to be using a codec with the file to convert it.  The Python codecs module has a convenient function, EncodedFile, that can eliminate most of the headaches of transcoding.  If you do need to convert the file, I can provide more information.

Note also that for files that are not too huge, Notepad can convert them.  Just open the file as what Notepad refers to as Unicode and save it as what it calls ANSI.  Of course, if there are characters not representable in the Windows code page in use, they will be lost this way.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Pirritano, Matthew
Sent: Tuesday, April 07, 2009 4:48 PM
To: [hidden email]
Subject: [SPSSX-L] does spss require ascii characters

I am trying to read in a dataset that is encoded as Unicode utf-16. I've
gotten help from the folks on the python list to create some code to
translate it into ascii. But I get the following error:

Traceback (most recent call last):
  File "C:\Projects\unicode_convert.py", line 8, in <module>
    outp.write(outLine.strip()+'\n')
UnicodeEncodeError: 'ascii' codec can't encode characters in position
640-641: ordinal not in range(128)


My question is, is there a way to read non-ascii characters?

I've tried setting the character encoding for data and syntax as Unicode
and then opening my data, which is in the form of a text file, but I
cannot read the file.

Do I have to convert this file first? That's what I've done in the past,
but this time I'm getting this error and so am looking for a possible
workaround.

Thanks
matt



Matthew Pirritano, Ph.D.
Research Analyst IV
Medical Services Initiative (MSI)
Orange County Health Care Agency
(714) 568-5648

=====================
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

=====================
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
|

rearranging variable order in python syntax block

mpirritano
Dearest listers,

In order to run the following repeat-end repeat syntax I need to reorder
some variables:

do repeat datevar = fromdatesvc to datepaid
                  /year = fromdate_year to datepaid_year
                  /month = fromdate_month to datepaid_month
                  /day = fromdate_day to datepaid_day.
        COMPUTE year =CHAR.SUBSTR(ltrim(rtrim(datevar)),1,4).
        compute month = char.substr(ltrim(rtrim(datevar)),6,2).
        compute day = char.substr(ltrim(rtrim(datevar)),9,2).
    end repeat.
    EXECUTE.

To reorder I'm using this syntax:

save outfile = 'G:/Data/AMM/SPSS_Files/recent.sav'
      /keep fromdatesvc datefrom dateto daterecd datepaid all
      /map.

This is all within a python spss.submit block. If I leave out a get file
command to get this recent.sav file I get an error that it cannot do the
repeat command. This is obviously because the variables are not
correctly ordered. So then I add the get file line and get the following
error:

The document is already in use by another user or process.  If you make
changes to the document they may overwrite changes made by others or
your
changes may be overwritten by others.
File opened g:\data\amm\spss_files\recent.sav

I also get the error that each of the variables that I create for the do
repeat block are already created.

When I look at the data it appears that everything works out okay, but
I'm not sure with all of the error messages I'm getting. Any ideas on
how to get rid of the error messages, or can I just ignore them.

Let me know if more info is needed to answer the question.

Thanks
Matt


Matthew Pirritano, Ph.D.
Research Analyst IV
Medical Services Initiative (MSI)
Orange County Health Care Agency
(714) 568-5648

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Peck, Jon
Sent: Tuesday, April 07, 2009 4:12 PM
To: [hidden email]
Subject: Re: does spss require ascii characters

Are you just trying to read a text into SPSS?  Are all the characters
plain 7-bit ascii?  Does the file have a BOM (byte order mark) at the
start?

The DATA LIST command can read utf-16.  You can specify ENCODING=UTF16,
and it should lap it right up.  Best if SPSS is running in Unicode mode
for this.

As far as the Python code below goes, your translation code is probably
wrong.  You need to be using a codec with the file to convert it.  The
Python codecs module has a convenient function, EncodedFile, that can
eliminate most of the headaches of transcoding.  If you do need to
convert the file, I can provide more information.

Note also that for files that are not too huge, Notepad can convert
them.  Just open the file as what Notepad refers to as Unicode and save
it as what it calls ANSI.  Of course, if there are characters not
representable in the Windows code page in use, they will be lost this
way.

HTH,
Jon Peck

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Pirritano, Matthew
Sent: Tuesday, April 07, 2009 4:48 PM
To: [hidden email]
Subject: [SPSSX-L] does spss require ascii characters

I am trying to read in a dataset that is encoded as Unicode utf-16. I've
gotten help from the folks on the python list to create some code to
translate it into ascii. But I get the following error:

Traceback (most recent call last):
  File "C:\Projects\unicode_convert.py", line 8, in <module>
    outp.write(outLine.strip()+'\n')
UnicodeEncodeError: 'ascii' codec can't encode characters in position
640-641: ordinal not in range(128)


My question is, is there a way to read non-ascii characters?

I've tried setting the character encoding for data and syntax as Unicode
and then opening my data, which is in the form of a text file, but I
cannot read the file.

Do I have to convert this file first? That's what I've done in the past,
but this time I'm getting this error and so am looking for a possible
workaround.

Thanks
matt



Matthew Pirritano, Ph.D.
Research Analyst IV
Medical Services Initiative (MSI)
Orange County Health Care Agency
(714) 568-5648

=====================
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

=====================
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

=====================
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