# st: RE: Macro and Loop

 From "Howrey, Bret T." To "'statalist@hsphsun2.harvard.edu'" Subject st: RE: Macro and Loop Date Mon, 8 Sep 2008 11:37:07 -0500

Assuming your data is in long format - If you reshape your data to wide format you can very easily compare each of the various values.  Then something like gen insurance=(mo1=="yes")+(mo2=="yes")+..(mo12=="yes") would generate a dichot val for you.

Bret

-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of Ying Huang
Sent: Monday, September 08, 2008 11:26 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: Macro and Loop

Dear all,

I am stuck in a Stata programming problem in work, and I wonder if you can help me out. I am working on a survey data right now and the data is in person level. And we want to see if a sample person had some kind of insurance coverage during a one-year period starting from the survey.

The first variable is the month of survey. It's numeric and goes from 1
to 12.   And then I have 24 indicator variables (1/0) to indicate
insurance coverage in 24 monthes. For example, if the survey is in 1997, then the survey month refer to Jan to Dec of 1997, and those 24 variables show insurance coverage for each month in 97 and 98.

The variable I want to create is again a 1/0 variable, say call it "insurance". Starting from the survey month, if any of the following 12 insurance coverage indicators = yes, then insurance =1; otherwise insurance =0.

I guess this would involve a macro and a forvalues loop. I tried to generate local macro a = interview month and b = interview month +12; then I tried to put "a" and "b" in a forvalues loop. But it did not work.

Thanks a lot for your help!!

Ying
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/