Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

st: Foreach loops for each variable.


From   natasha agarwal <[email protected]>
To   [email protected]
Subject   st: Foreach loops for each variable.
Date   Thu, 22 Nov 2012 19:42:05 +0000

Hello Stata users,

I have a understanding failure here in how the foreach loop is
working. I have a dataset with 40 countries spanning from 1980-2004.

Now for each country I have to create a variable which is going to
look like follows:

gen agri_1980 = Dst1980 if pa=="Agriculture, Hunting and Forestry" & year==1980
gen mini_1980 = Dst1980 if pa=="Mining and Quarrying" & year==1980
gen basic_1980 = Dst1980 if pa=="Basic Metals and Fabricated Metal" & year==1980
gen construction_1980 = Dst1980 if pa=="Construction" & year==1980
gen electrical_1980 = Dst1980 if pa=="Electrical and Optical
Equipment" & year==1980
gen electricity_1980= Dst1980 if pa=="Electricity, Gas and Water
Supply" & year==1980
gen financial_1980 = Dst1980 if pa=="Financial Intermediation" & year==1980
gen food_1980 = Dst1980 if pa=="Food, Beverages and Tobacco" & year==1980
gen hotels_1980 = Dst1980 if pa=="Hotels and Restaurant" & year==1980
gen mach_1980 = Dst1980 if pa=="Machinery, nec" & year==1980

Basically here I am just creating variables that takes the values of
Dst for a particular industry in 1980. I have to do the same for all
the years and then over 40 countries. I tried doing it following
Nick's advice on how to use foreach for each values in the variable,
but failed.

Is there anybody that could help me with the same, I would be grateful.

Thanks,
Natasha
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index