Creating a new variable

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

Rutger88
Posts: 3
Joined: Wed Nov 09, 2011 10:33 am

Creating a new variable

Postby Rutger88 » Wed Nov 09, 2011 11:34 am

At the moment with a dataset in panel format. for a population with 3,1 million individuals with yearly observations from 2005 till 2008. In this file there is variable that states the amount of pension entitlements(numeric) an individual has in period t. Now I need to create a new variable where I want to assign a 1 to an individual when his yearly entitlements have decreased compared to the previous year. Below I have given a design of my dataset, where the pension variable is the variable I want to create, with this information: person, year and entitlement.
To be clear, a 1 should be assigned when I observe individual A, B etc. that his or her entitlement has decreased compared to the previous year.
What is the most effective way to create this variable?

Person, year, entitlement, Pension
Individual A, 2005, 40, 0
Individual A, 2006, 50, 0
Individual A, 2007, 40, 1
Individual A, 2008, 30, 1
Individual B, 2005, 20, 0
Individual C, 2005, 40, 0
Individual C, 2006, 30, 1
Individual C, 2007, 20, 1
Individual D, 2005, 10, 0
Individual D, 2006, 20, 0
Individual D, 2007, 30, 0
Individual D, 2008, 40, 0


Thanks in advance!
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Creating a new variable

Postby GerineL » Wed Nov 09, 2011 11:57 am

do you have the same amount of entries for each person?
Rutger88
Posts: 3
Joined: Wed Nov 09, 2011 10:33 am

Re: Creating a new variable

Postby Rutger88 » Wed Nov 09, 2011 12:22 pm

No it is unbalanced.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Creating a new variable

Postby GerineL » Wed Nov 09, 2011 3:00 pm

not the most elegant way, but it will work:


- make sure they are in the right order (sort by person; year)
- create a lag for person (person_1) and a lag for entitlement (entitle_1)
using: transform -> shift values.

- create if function like this:

if ((person = person_1) & (entitlement < entitlement_1)) pension = 1.
execute.
recode pension (sysmis = 0).
execute.
oken
Posts: 9
Joined: Thu Nov 10, 2011 7:26 am

Re: Creating a new variable

Postby oken » Thu Nov 10, 2011 8:14 am

I agree with the use of the data transform command. That is simply the best way to work with the data in an easy single-click way but make sure that the code you write for the transform is done properly.
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Creating a new variable

Postby GerineL » Thu Nov 10, 2011 10:33 am

oken wrote:I agree with the use of the data transform command. That is simply the best way to work with the data in an easy single-click way but make sure that the code you write for the transform is done properly.

????
Rutger88
Posts: 3
Joined: Wed Nov 09, 2011 10:33 am

Re: Creating a new variable

Postby Rutger88 » Thu Nov 10, 2011 11:07 am

Thank you Gutnre, that worked perfectly

Who is online

Users browsing this forum: No registered users and 1 guest

cron