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

# st: looping panel data

 From Tomáš Houška To statalist@hsphsun2.harvard.edu Subject st: looping panel data Date Tue, 4 Oct 2011 12:56:58 +0200

```Hi statalist,

I would like to ask you for a help with my looping problem. I have
sales panel data with variables week ID, store ID, product ID, price,
expenditure_share (share of expenditures for a given product across

I would like to compute Stone price index defined as P_nt=SUM
(expenditure_share_int * P_int ). This means that for each combination
of store (n) and week (t) I need to compute a multiple of
expenditure_share and price for each product (i) and then sum it up
over all products sold in the particular store that week. The result
is again a panel data variable P_nt which is a price index for each
week and store. It is an expenditure system index, so the more you
spend on more expensive products (keeping prices constant), the higher
the index.

And I cannot figure out a way how to calculate P_nt index. I have come
up with a loop, which saves the results in a new dataset, but it is
not working. I would be very glad for any help on how to calculate
this variable.

Here is my looping command (j=week number, store_number is a local
macro with list of store numbers - they are from 2-131 but with
missing values (i.e. not consecutive))

postfile index_file store week index using stone_index_res, replace
foreach store in `store_number' {
forvalues j=91/317 {
gen index`store_number'`j' = exp_share9401000* avgp9401000+
exp_share9401870* avgp9401000+ exp_share9402500* avgp9402500+
exp_share9402600* avgp9402600+ exp_share9405400* avgp9405400+
exp_share9408160* avgp9408160+ exp_share9410100* avgp9410100+
exp_share9410200* avgp9410200+ exp_share9450850* avgp9450850+
exp_share9451200* avgp9451200+ exp_share9451000* avgp9451000 if
week==`j' & store==`store_number'
post index_file (`week') (`store') (index`store_number'`j')
}
}
postclose index_file