Announcement

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

  • Replace value in one row based on another variables

    ID year open near_2 near_3 competition exposed
    1 2005 1 1 1 0 0
    1 2006 1 1 1 0 1
    1 2007 1 1 1 0 1
    2 2005 0 1 0 0 0
    2 2006 1 1 0 1 0
    2 2007 1 1 0 0 0
    3 2005 0 0 1 0 0
    3 2006 0 0 1 0 0
    3 2007 1 0 1 1 0
    Hi,

    Im working with a panel data and I want to identify when a grocery store is exposed to competition, meaning when one store is opening less than 3km close to a store that is already opened. My competition variable attains value 1 for when that store is exposing another store for competition. The "exposed" variable is an indicator of which store that is exposed to competition by other stores. Im new to STATA so im having issues with generating my "exposed" variable.

    I want to generate a variable "exposed" that attains value 1 for those years when other units are exposing that store for competition, which in my case is when other stores(ID 2 & 3) competition variable attains the value of 1 and and are close to ID=1 which is open the whole period.

    Btw. I cannot install any packages on the computer im using STATA on.


    Thanks!
    Last edited by Berit Alsson; 23 Mar 2023, 03:53.

  • #2
    https://www.stata.com/support/faqs/d...ng-properties/ may help.

    A principle there which can unlock some problems is

    total of others IS total for all MINUS this value


    I don't think I understand your data structure fully. Naturally you've given us a simple toy example but in the full dataset are there hundreds of indicators near_4 near_5 and so on?

    Comment


    • #3
      Im sorry for not being more specific with my dataset before. So I have a panel data with 160 units(ID=grocery store) over 14 years(2005-2018).

      The "near_ID" variable is ==1 when another variable (which I have not listed above) "distance_ID" (spdistance ID ID) is less than 3km. Its hard to describe but i have looped these so I have a total of 160 "near_ID" variables, so each "near_ID" variable are indicators if for example "near_3" are less than 3km to ID: 1,2,...,160. I have a total of 160 "distance_ID" variables as well. So some units are opened the whole period and some are not, and both of these can be exposed to competition as long as there are a new unit opened nearby.

      Im not sure I understand the principle you mentioned?

      Comment


      • #4
        The principle I spelled out is discussed at greater length in the linked FAQ. but it is easy enough to expand on. Suppose you want the average age of other members of a family. Then a way to get at that is to

        calculate the total age of a family

        subtract individual age in each observation

        divide by (number of members in a family - 1).

        Thanks for the extra detail, which should be helpful to others interested in your question. I don't have time at the moment to try to puzzle out any code.

        Comment


        • #5
          Thanks for your reply.

          I understand your principle and have tried some of the codes in the linked FAQ and in my understanding, the by command is only applying the commands within each group you specify in by(). But I want to specify exposure==1 based on conditions based on other groups, (when ID!=ID) which is the opposite from what I get when I use by().

          If grocery store 1 have been open since forever, and another grocery store 2 opens nearby this year 2023, then grocery store 1 is exposed==1 in 2023 due to grocery store 2 is exposing other to competition==1. The reason why store 2 is exposing 1 to competition is because its closer than 3km, meaning near_2==1

          And I think I would solve my problem with the FAQ you sent me and just a little guidance to how to apply ID!=ID in some sense because I have failed many times.

          Thanks!


          Comment


          • #6
            I still haven't solved my problem. Do I repost the same question ??

            Comment


            • #7
              There is no point in re-posting the same question unless you can improve it.

              Speaking just for myself, this was and is a problem I partly understand. We're all volunteers here (if not StataCorp employees) and in this case I am not inclined to spend time on it that might get nowhere. Sorry if that seems disappointing, and sorrier if it seems rude, but there you go. Some of us will spend time discussing questions that we find interesting and that are close to what we usually do, but otherwise you may be unlucky.

              Comment

              Working...
              X