Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: generating a variable?

From   Ignacio Martinez <>
Subject   st: generating a variable?
Date   Thu, 28 Jul 2011 15:10:50 -0400


I'm having troubles generating 2 new variables with my data.

I have the following variables: ID; E01-E12 where E01 =3 indicates
that i is enrolled in a 4 year college in January, and E05=2 means
that he is enrolled in a 2 year college in may.

I want to generate a 2 new variables Total_2_year that is the total
number of month that i is enrolled in a 2 year college and
total_4_year that is the total number of month that i is enrolled in a
4 year college.

What is the best way of doing this?

My first attempt was this
*Generates vectors of total months enrolled in college
gen total_2_year = 0
gen total_4_year = 0
gen total_none = 0

forvalues month=1/9 {
		if 511200`month'==3 then total_4_year==total_4_year+1
		if 511200`month'==2 then total_2_year==total_2_year+1
		if 511200`month'==1 then total_none==total_none+1
		if 511200`month'==-4 then total_none==-4		
		if 511200`month'==-4 then total_2_year==-4
		if 511200`month'==-4 then total_4_year==-4										


but i get only zeros... :_(

Thanks a lot

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index