Statalist The Stata Listserver


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

st: Not sure if -foreach- is best option


From   "Reza C. Daniels" <[email protected]>
To   <[email protected]>
Subject   st: Not sure if -foreach- is best option
Date   Fri, 2 Feb 2007 11:43:39 +0200

Dear Statalisters,

I have two tasks that I've been thinking -foreach- can solve, but I'm not
sure anymore. I've checked the help files and Statalist archives and haven't
found a solution. My problem is simple and I'm sure there is a very quick
solution. Here's the task.

The structure of my data is as follows:

a) I have tariff data for 81 commodities. Each tariff variable is a
constant>1.
b) I have matching household expenditure data for 81 commodities.
c) Note that there are 25,000 households and the calculations are therefore
being made at the household level.

Syntax for variable names:
a) each of the 81 tariff lines are separate variables named: tff1 (through
tff81--all constants).
b) each of the 81 expenditure lines are separate variables named: exp1
(through exp81).

I want to work out revenue from tariffs assuming full pass through
(economist speak for ignoring everything that matters) of tariffs to
domestic prices. Here are the analytical steps:

1) Calculate world prices as domestic expenditure / tariff.
2) Calculate revenue derived from tariffs as expenditure - world prices. I
want these as separate variables because they'll be used for different
purposes later in the analysis, so I don't calculated revenue in one step
(exp* - exp* / tff*).
3) After these quantities are estimated at the household level, I can then
calculate total household expenditure on tariffs and total tariff revenue at
the national level, but I do not want to include these in my -foreach- loop.

My question: How do I go about creating the 162 new variables (81 world
price variables and 81 household expenditure on tariff variables) required
in steps (1) & (2) above? Note that I want to keep the data at the household
level and therefore my seemingly inefficient structure of 162 new variables
has some logic to it. I have tried the following:

***
foreach var of varlist tff* {
 	gen wp* = exp* - exp* / tff*
 	gen rev* = exp* - wp*
}
***

However my syntax is wrong as you can very quickly see. Clearly my problems
are that (A) the varlist is not tff* and actually I want to create new
variables without necessarily going through each of anything, and (B) I
don't know how to generate a new variable with the same variable naming &
numbering convention that I have in my tariff and expenditure var names.

Sorry for the long and cumbersome explanation, but I thought it necessary.
Any suggestions would be appreciated.

Thanks,
Reza

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