Bookmark and Share

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

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

st: looping panel data

From   Tomáš Houška <>
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
all products in dataset)

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

Thank you for your help!

*   For searches and help try:

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