Announcement

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

  • How to generate a new variable big/small size of the firm using size vari

    Hi , I am trying to generate a new variable (big or small size) using firm size for each company. I am using a balance panel data set and the following code. However, this give me median for each year which not distinguish firms by id. Could you assist me. I am new to this forum and i am sorry if my question is not relevant.

    Code:
    bysort industry year : egen mean=mean(size)
    bysort industry year : egen median_size= median(size)
    companyid
    Year BL PBL Prof Tang Size
    1 2011 0.24578 0.24578 -1.023654 0.0854623 7.72
    1 2012 0.21546 -0.00254 -1.236472 0.42552 7.74
    1 2013 -1.02454 0.23647 0.023654 0.61234 7.74
    1 2014 -0.00254 0.256742 0.32546 0.25463 7.74
    1 2014 0.65849 0.02354 0.035684 1.32654 7.74
    1 2016 1.23654 1.02456 0.054861 1.36542 7.74
    2 2011 -0.02154 0.21354 -0.32546 -0.36654 5.29
    2 2012 -1.23514 0.02354 -0.536248 -0.02365 5.18
    2 2013 0.02364 1.02457 -0.002546 -0.25489 4.91
    2 2014 0.00267 1.32456 -1.325647 -0.3845 4.68
    2 2015 0.23654 1.30564 -0.32564 -0.23654 4.68
    2 2016 0.04567 1.06547 0.32651 -.23651 4.80
    3 2011 1.03547 1.002546 0.56421 0.2364541 6.84
    3 2012 1.25413 1.032546 1.019435 0.25641 6.92
    3 2013 1.5427 0.145764 1.036541 0.65347 6.96
    3 2014 1.56423 1.02354 1.32654 1.05432 6.82
    3 2015 1.02456 0.23548 1.621350 1.68452 6.98
    3 2016 1.24531 1.023546 1.325416 1.32546 7.07
    Last edited by muhammad ayaz; 08 Aug 2018, 09:58.

  • #2
    Welcome to the Stata Forum / Statalist,

    Thanks for having tried to use the CODE delimiters. Unfortunately, a wrongly positioned bracket is reponsible for the failed attempt.

    That being said, sharing data (mock, abridged, etc.) is the best way to entice a useful reply. You may use - dataex - for that matter.

    If I understood right, you wish to create a binary variable according to a given cut-off value. Provided you "by sort" correctly, something as - gen binvar = firmsize >= ### would probably do the trick. Following you example, it could be - gen binvar = 1 if firmsize > median_size.
    Last edited by Marcos Almeida; 08 Aug 2018, 09:41.
    Best regards,

    Marcos

    Comment


    • #3
      I happen to have done this just yesterday, but you're gonna need to give us a lot more information if you actually want a helpful information. Anyways, some tips to get started.

      I'm assuming you're creating some sort of portfolios. If you re-balance portfolios on size yearly, then you'd also need to classify firms into Small/Big each year. Because firms can have large growth and go from smaller to bigger or the other way around.

      For example, if you want to sort your firms into ten groups based on their size. You could do something like this:
      Code:
      //Create size decile
      gen size_decile = .
      foreach i of numlist 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 ///
      1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 ///
      2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 {
      xtile decile_temp=size if year==`i', nq(10)
      replace size_decile = decile_temp if missing(size_decile)
      drop decile_temp
      }
      This would rank all your firms by year and then based on size. So, for each year the smallest firm have size_decile marked as 1 and the highest firm are marked with 10.

      Usually, you'll want to know something like the mean-return of similarly sized firms. You can do something like this:
      Code:
      bysort year (size_decile): egen mean_return = mean(return) if !missing(size_decile)
      I hope these tips can help you get started. But if you want a more specific answer, you'll need to ask a more specific question I'd say!

      Comment


      • #4
        Thank you so much Marcos Almeida and Jesse Tielens for your input. Indeed both are efficiently works.
        Regards

        Comment

        Working...
        X