Copy variables between cases using an array

Discussions about editing and cleaning data
Post Reply
Don
Posts: 55
Joined: February 15th, 2013, 1:28 pm
Location: Barbados

Copy variables between cases using an array

Post by Don »

Hi I just want to see if I'm doing the right thing.

In the survey I'm batch editing, I have some rented rooms within a house that were enumerated as separate households even though they are a part of the same building. This was done on purpose. The problem is that no information on the walls or roof was collected for these rooms although it was recorded for the main house. I know that the walls and roof would be the same as the main house.

The solution I came up with was to create an array for each missing variable where the indices are the ID items and the data is the missing info. I used the following code to accomplish this:

Code: Select all

if H8 = 2 then		//if separate house with rented room 
	RentedRoomsH11(ED,HOUSEHOLD) = $;		//populate array with info
elseif H8 = 3 then		//if rented room in separate house
	impute($,RentedRoomsH11(ED,HOUSEHOLD));		//impute same wall as separate house with rented room
endif;
I repeat this for each variable. Just wondering if I'm on the right track
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Copy variables between cases using an array

Post by Gregory Martin »

That should work, especially if you the number of households you have is sufficiently small to store in an array. That also assumes that code 2 will occur before any code 3. If not, then your array wouldn't be updated with the proper code. If that were the case, you could make your array a save array (add the keyword save after the array declaration), and then run your program twice. On the first run the array would be set up with all the proper values, and on the second run you would use those values for the imputation.

If you have too many households to fit in an array, you could use an external file to store the wall information, and then writecase/loadcase from the file to get the proper value for imputation.
Post Reply