Announcement

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

  • Multiplying values within the variable given certain conditions

    Hello everyone,

    Below, you will find a structure of a similar dataset that i am using. The data consists of all companies present in a given year for the period 1996-2015. Also the company's industry code is known, as well as the city's yearly growth. I am trying to generate the total growth of a city between 1996 - 1998 by multiplying the yearly growth numbers from - GrowthYear -. This will be put in the variable - Growth1996_1998 -. The variable - Growth1996_1998 - will thus be the same all observations that have the same city where the years fall between 1996-1999. Obviously, i can not multiply every value found in the -GrowthYear - variable, as this will lead to an overestimation of the growth between 1996 and 1998. Therefore, i want to multiply the values from - Growthyear - where - CompanyNumber - < 2 & - Year - < 1999 so that each yearly growth number is represented only once in the end result. Finally, i want the value for -Growth1996_1998- to be equal for all companies across years and all industries that are located in the city for the period 1996-1998. This is represented as the Xs, Ys, and "." found in the dataset under - Growth1996_1998 -

    I have found the code suggested in a similar, but easier example (see link below). Unfortunately, this did not work for my database.
    HTML Code:
    https://www.statalist.org/forums/forum/general-stata-discussion/general/75096-how-to-multiply-observations-within-a-variable-in-stata
    City (string) Year (string) Industry_code (String) CompanyNumber (string) GrowthYear (double) Growth1996_1998 (double)
    A 1996 1 1 1.025 X
    A 1996 1 2 1.025 X
    A 1996 1 3 1.025 X
    A 1996 2 1 1.025 X
    A 1996 2 2 1.025 X
    A 1997 1 1 0.98 X
    A 1997 1 2 0.98 X
    A 1997 1 3 0.98 X
    A 1997 1 4 0.98 X
    A 1997 2 1 0.98 X
    A 1997 2 2 0.98 X
    A 1997 3 1 0.98 X
    A 1997 3 2 0.98 X
    A 1997 3 3 0.98 X
    A 1998 1 1 1.02 X
    A 1998 2 1 1.02 X
    B 1996 1 1 1.01 Y
    B 1996 2 1 1.01 Y
    B 1996 3 1 1.01 Y
    B 1996 3 2 1.01 Y
    B 1997 1 1 1.03 Y
    B 1997 1 1 1.03 Y
    B 1997 2 2 1.03 Y
    B 1997 2 2 1.03 Y
    B 1998 1 1 1.10 Y
    B 1998 2 1 1.10 Y
    B 1998 2 2 1.10 Y
    B 1999 1 1 0.95 .
    B 1999 2 1 0.95 .
    I hope that someone can help me out. Feel free to ask any question.

    Kind regards,

    Patrick
    Last edited by Patrick Johnson; 28 Jul 2018, 09:41.

  • #2
    Please post your data using the -dataex- command described in section 12.2 in the FAQ https://www.statalist.org/forums/help.
    Stata/MP 14.1 (64-bit x86-64)
    Revision 19 May 2016
    Win 8.1

    Comment


    • #3
      No need for a new topic, just continue to post here.
      Stata/MP 14.1 (64-bit x86-64)
      Revision 19 May 2016
      Win 8.1

      Comment


      • #4
        Dear Carole,

        Unfortunately, I am not able to change the format anymore in this post.

        Kind regards,

        Patrick
        Last edited by Patrick Johnson; 28 Jul 2018, 10:19.

        Comment

        Working...
        X