Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Code help - nested data

    The structure of my data (attached file statalist_Nov25.dta) looks like the following. There are 'n' persons in my data (person_ID). Each of these people shop products over time, indicated by shopping_ID of the product. There is some exogenous shock/s during the purchase of products over time (shock_ind - 0/1 dummy variable). Final observation is on the number of units purchased over each shopping trip (no_units)

    1. person_ID
    2. shopping_ID by person
    3. shock_ind
    4. no_units

    I need coding help in the following:

    1. How do I create a variable shock_ind_2 which has value 0 during all shopping trips before the break and 1 after the first shock?
    2. At the break stage (0 to 1 switch e.g. observation 13 & 14) I want to take difference in the purchase units for each customer for each of the shocks.
    3. If there are two shocks for a customer, all his observations are divided into three parts - part 1 before first shock, part 2 between first and second shock, part 3 post second shock and final observations. I want to take average, sum, min, max of purchase units for all these parts, by customer. (e.g. observation 14 & 17 for person_ID "2")
    4. For any customer, I want to take difference or gradient between the first shopping trip no_units vs. last shopping trip no_units. (e.g. difference between no_units for obs. 1 & 10)


    Thanks,
    Guneet
    Attached Files

  • #2
    I suppose you will increase the chance of a good reply if you put some example of your data as the likelihood is small that someone will be interested to download and open a dataset to provide you a solution. Please read the FAQ on how to provide data example also see this thread for a better understanding of what I said : http://www.statalist.org/forums/foru...-for-statalist
    Roman

    Comment

    Working...
    X