Statalist The Stata Listserver


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

st: RE: Looping across variables in variable columns


From   "Maarten Buis" <[email protected]>
To   <[email protected]>
Subject   st: RE: Looping across variables in variable columns
Date   Thu, 26 Apr 2007 13:22:25 +0200

--- Mungai, Edward wrote:
> We aim to test that parents economic performance being good, 
> denoted  (1) or bad, denoted (0) when children are ages 16 years 
> and 17years may influence the children career behaviour even 
> much later in life.
>
> We have the information on the parental economic perfomance for a 
> period of years, 1970 to 1972 in this example. We also know the 
> years when the children were 16yrs and 17yrs which may, may-not 
> or only partially overlap with the years of parental economic 
> perfomance which we have available.
>
> For years when the parental influence is not available, we assume 
> the influence was bad i.e. value zero in the example.
>
> The problem is to get a stata loop to compute the total parental 
> influence for each child.
>
> In the example, this total would be 2 for Mark, 1 for Paul and 0 
> for John. 
>
> Child ParInf1970 ParInf1971 ParInf1972 Yr16yrs Yr17yrs 
> Mark  1          1          1          1970    1971              
> Paul  0          1          0          1971    1972                 
> John  1          1          0          1972    1973                


One way of doing this is shown in the example below. 

However I doubt whether saying that the parents influence is bad if 
you don't have information about it is a good strategy, especially 
since this information is missing because the childeren don't belong 
to the right cohort. A much better way would be to code them as 
missing. You could than use -ice- (see: -ssc desc ise-) for multiple 
imputation of ParInf16 and ParInf17 (and passively impute TotParInf). 

Hope this helps,
Maarten

*--------------------- begin example ------------------
drop _all
input str4 Child ParInf1970 ParInf1971 ParInf1972 Yr16yrs Yr17yrs
Mark	 1	 1	 1	 1970	 1971 	      	
Paul	 0	 1	 0	 1971	 1972	       	
John	 1	 1	 0	 1972	 1973	          
end

gen ParInf16 = cond(Yr16yrs == 1970, ParInf1970, /*
           */  cond(Yr16yrs == 1971, ParInf1971, /*
           */  cond(Yr16yrs == 1972, ParInf1972, 0)))

gen ParInf17 = cond(Yr17yrs == 1970, ParInf1970,  /*
           */  cond(Yr17yrs == 1971, ParInf1971,  /*
           */  cond(Yr17yrs == 1972, ParInf1972, 0)))


gen TotParInf = ParInf16 + ParInf17
*--------------------- end example -----------------------
(For more on how to use examples I sent to the Statalist, see:
http://home.fsw.vu.nl/m.buis/stata/exampleFAQ.html )


-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology 
Vrije Universiteit Amsterdam 
Boelelaan 1081 
1081 HV Amsterdam 
The Netherlands

visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434 

+31 20 5986715

http://home.fsw.vu.nl/m.buis/
-----------------------------------------





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