Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Recode problem


From   [email protected]
To   [email protected]
Subject   st: Recode problem
Date   Thu, 16 Feb 2006 22:39:02 +0100 (CET)

Dear all,

I encountered a problem while trying to "recode" a dataset. Actually, I
tried to somewhat "harmonize" party labels in a dataset containing
comparative election studies.

So, here is the point: I do a "foreach" loop across a set of variables.
For each set of observations (e.g. the Australian elections of 1996 or the
Belgish elections of 1999) some of the variables (e.g. presidential vote
decisions, parliamentary vote decision etc., discrete scales) are present,
others are missing.

Here is the code:

-----
foreach var of varlist vote_pres vote_1 vote_2 close_1 close_2 close_3 {
* AUS_1996
recode `var' (1=2) ///
 (2=1) ///
 (6/max=.) if label=="AUS_1996",test

*BEL_1999
recode `var' (2=5) ///
 (3=3) ///
 (4=1) ///
 (6=4) ///
 (7=7) ///
 (8=2) ///
 (1 5 9/max=.) if label=="BELF1999",test

etc

-----

Here is the problem: In my first case, the Australian elections, the first
variable "vote_pres" is missing since there are no presidential elections
in this country. But if I exectute the above cited code Stata converts the
ENTIRE variable "vote_pres", not just for the Australian election, but for
any other election in the dataset, to missing. Thus,

-----

. recode vote_1 (1=2) (2=1) (6/max=.) if label=="AUS_1996"
(vote_1: 0 changes made)

-----

may be a bit misleading. What is the point? Did I commit some foolish
error, or is there any kind of systemic error?

Thanks a lot,

Guido
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index