Announcement

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

  • #16
    Please bear in mind that as someone outside your field I don't have any precise knowledge of what portfolio, event, etc. mean at all.

    But levelsof may help.

    But why do you need the company identifiers any way? They're the companies in one of your bins: isn't the bin identifier enough?

    Comment


    • #17
      My apologies, this is an event study analysis where i look at what happens to stock returns (the abnormal returns) after a shock to the market (marked by an event day).
      The company's (10,14,...122) together form the portfolio/group of firms which i want to total abnormal returns for, on each of the days 1->20 after the event date.

      Ideally I'd want to use something like the following, but the syntax is invalid.
      Code:
      keep company_id if percentiles==10
      And then run the code
      Code:
      forval d = 0/20 {      
      capture {          
      total abnormal_return if days==`d'          
      local D : di %02.0f `d'          
      estimates store CAR`D'1W


      Comment


      • #18
        Sorry, but I don't see what that syntax would even do if it were valid. keep with variables keeps only those variables. You don't want to throw out all variables other than company identifier so far as I can see.

        Conversely, if you keep just one decile bin using an if condition, then the companies left are those you want any way, are they not? Equivalently your last block of code doesn't depend on, or even use, the information on which companies are included.

        Comment


        • #19
          The deciles (top and bottom) are made on day 0, and then the same companies which make up those deciles are needed on each of the following days 1 to 20. If i keep just one decile bin, that keeps only the observations for the company identifiers on day 0. While i want only those companies for all the days.

          Since i want to run this over 207 events, I guessed that the best way to code the problem would be to have stata recognise which companies belong to the top/bottom decile bins, then cut down the dataset to only those selected firms, before totaling the abnormal returns. But i'd like it to be able to do this automatically without me inputting the company identifiers for the top and bottom deciles each time.

          Comment


          • #20
            OK; that helps. I've already suggested levelsof in #16.

            Comment


            • #21
              Thank you for all your help so far Nick,
              I've spent the last day playing around with 'levelsof' and become rather stuck again.

              Following Clyde's reccomendations on "https://www.statalist.org/forums/forum/general-stata-discussion/general/103576-use-elements-of-a-local-as-argument-for-inlist-function"

              I tried the egen function anymatch(), but i have the problem of the invalid numlist (since the company_ids aren't separated by commas).

              Code:
              egen var3 = anymatch(company_id), values(r(winner))
              *values() invalid -- invalid numlist   r(121)*
              I tried to use the local macro 'winner', and then transform it so that i would be able to
              use the 'inlist' which needs a list of arguments seperated by commas. But i get the following error:

              Code:
              levelsof company_id if percentiles==10, local(winner)
              replace r(winner) = subinstr(r(winner), " ", ",",.)
              *r101 factor-variable and time-series operators not allowed*
              I'm at a loss as to how i can solve the latest error!

              Comment


              • #22
                In general the only way to change r-class results is to overwrite them with an r-class command. replace is for variables in your data (only).

                But a local macro isn't an r-class result any way.

                I suggest

                Code:
                levelsof company_id if percentiles==10, local(winner)  
                local winner : subinstr local winner " " ",", all
                This should also work for modest numbers of values:

                Code:
                local winner = subinstr(`"`winner'"', " ", ",", .)

                Comment


                • #23
                  Thank you again for all your help. That coding works perfectly.

                  Comment


                  • #24
                    Hi all,

                    I'm working with panel dataset containing 195 countries (see example below).

                    However, I only need a subset of countries, which is why i tried dropping some of the countries using

                    Code:
                    drop if inlist(country,"Albania","Algeria","Andorra","Angu illa","Antiqua_and_Barbuda","Australia","Austria", "Azerbaijan")
                    I do not get an error code, but 0 observations are deleted:
                    Code:
                    . drop if inlist(country,"Albania","Algeria","Andorra","Angu illa","Antiqua_and_Barbuda","Australia","Austria", "Azerbaijan")
                    (0 observations deleted)
                    Has anyone experienced a similar problem and know the solution?

                    Thank you in advance!


                    Code:
                    * Example generated by -dataex-. To install: ssc install dataex
                    clear
                    input int year str25 country float rainfallmm
                    1988 " Afghanistan"     27.25257
                    1989 " Afghanistan"     26.55535
                    1990 " Afghanistan"    30.222525
                    1991 " Afghanistan"     36.28749
                    1992 " Afghanistan"     34.01302
                    1993 " Afghanistan"    26.423775
                    1994 " Afghanistan"     28.51853
                    1995 " Afghanistan"    25.074846
                    1996 " Afghanistan"    26.750185
                    1997 " Afghanistan"    27.604815
                    1998 " Afghanistan"     29.87177
                    1999 " Afghanistan"     24.60539
                    2000 " Afghanistan"    16.817682
                    2001 " Afghanistan"    15.403734
                    2002 " Afghanistan"     24.32237
                    2003 " Afghanistan"     27.39291
                    2004 " Afghanistan"     24.06963
                    2005 " Afghanistan"     29.60997
                    2006 " Afghanistan"     27.12046
                    2007 " Afghanistan"     25.32968
                    2008 " Afghanistan"    21.505365
                    2009 " Afghanistan"    31.106476
                    2010 " Afghanistan"    22.452065
                    2011 " Afghanistan"     25.53845
                    2012 " Afghanistan"     31.52742
                    2013 " Afghanistan"     28.91377
                    2014 " Afghanistan"    25.967264
                    2015 " Afghanistan"    33.449856
                    2016 " Afghanistan"    28.248095
                    1988 " Albania"        66.524025
                    1989 " Albania"         63.91075
                    1990 " Albania"         67.68621
                    1991 " Albania"         76.48907
                    1992 " Albania"         66.47468
                    1993 " Albania"        71.772896
                    1994 " Albania"         83.85102
                    1995 " Albania"         89.73432
                    1996 " Albania"         95.78157
                    1997 " Albania"         70.55569
                    1998 " Albania"         80.19603
                    1999 " Albania"         88.70529
                    2000 " Albania"         62.89793
                    2001 " Albania"         64.84759
                    2002 " Albania"         87.40131
                    2003 " Albania"         79.38502
                    2004 " Albania"         86.85091
                    2005 " Albania"         84.01238
                    2006 " Albania"         81.72401
                    2007 " Albania"         82.57442
                    2008 " Albania"         81.57327
                    2009 " Albania"        105.86436
                    2010 " Albania"        107.84811
                    2011 " Albania"         59.83802
                    2012 " Albania"         81.53146
                    2013 " Albania"         83.96725
                    2014 " Albania"         106.4032
                    2015 " Albania"         78.13724
                    2016 " Albania"         91.31202
                    1988 " Algeria"         6.719759
                    1989 " Algeria"         5.770886
                    1990 " Algeria"         7.478644
                    1991 " Algeria"         7.344397
                    1992 " Algeria"          7.33942
                    1993 " Algeria"         5.201967
                    1994 " Algeria"         7.242153
                    1995 " Algeria"         6.266937
                    1996 " Algeria"         8.494614
                    1997 " Algeria"          7.31943
                    1998 " Algeria"         5.362187
                    1999 " Algeria"         7.439788
                    2000 " Algeria"          4.36128
                    2001 " Algeria"          5.03195
                    2002 " Algeria"         5.633926
                    2003 " Algeria"         8.935742
                    2004 " Algeria"          8.43283
                    2005 " Algeria"         5.777586
                    2006 " Algeria"         8.015256
                    2007 " Algeria"         7.325529
                    2008 " Algeria"         6.621873
                    2009 " Algeria"          7.65311
                    2010 " Algeria"         7.745368
                    2011 " Algeria"         7.957712
                    2012 " Algeria"         6.898958
                    2013 " Algeria"         7.169009
                    2014 " Algeria"         6.193111
                    2015 " Algeria"         6.511808
                    2016 " Algeria"         5.449697
                    1988 " American Samoa" 274.34576
                    1989 " American Samoa"  240.0255
                    1990 " American Samoa" 198.81413
                    1991 " American Samoa" 264.01498
                    1992 " American Samoa"   268.401
                    1993 " American Samoa"  252.2328
                    1994 " American Samoa" 300.87372
                    1995 " American Samoa"  248.7933
                    1996 " American Samoa"  271.2207
                    1997 " American Samoa" 209.18135
                    1998 " American Samoa" 113.25059
                    1999 " American Samoa"  237.8423
                    2000 " American Samoa" 246.33046
                    end
                    Last edited by Katrine Marie Jensen; 20 Jul 2019, 12:47.

                    Comment


                    • #25
                      your data has spaces in front of the name but your code does not; see
                      Code:
                      help trim
                      to get rid of the spaces

                      Comment


                      • #26
                        Thank you so much Rich - sometimes you don't see the most obvious errors yourself .

                        Comment


                        • #27
                          There is a leading space in your data, but not in your search strings.

                          Comment


                          • #28
                            Hello everyone,

                            I have a time series with X years. I want to drop only the observations for variable year in year < 2013 & year > 2019.

                            I tried: drop if year<2013 & year>2019 but I got r(109) - type mismatch

                            Any suggestion?

                            Comment


                            • #29
                              it appears that your "year" variable is a string (which means you. need quotes around the values) but, in addition, year cannot be both <2013 and>2019 at the same time; you can still do as is:
                              Code:
                              keep in in range(year, "2014","2018")
                              or you could -destring- the variable and use any of a number of ways to do it

                              the above makes assumptions about your data, assumptions that could not be tested because you did not supply a data sample; see
                              Code:
                              h dataex
                              and also please read the FAQ, esp. about CODE blocks and -dataex-

                              Comment

                              Working...
                              X