Announcement

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

  • Using stateby to generate new variable

    Dear Statalist
    How I can use statsby command to save the coefficients of regression. I want to run a regression for each industry_id in each year, and save the coefficients of x1,x2,x3 as a new variables to use them later ( the coefficients x1,x2,x3 should be the same for the firms with the same industry_id in each year).
    my model is :
    y= x1+x2+x3
    the observations for the explanatory variables from the firms with the same industry_id in each year.
    I hope I was clear enough.

  • #2
    Code:
    statsby, by(industry_id year: regress y x1 x2 x3

    Comment


    • #3
      thank you the code work perfectly. How we can adjust the code so the generated file will contain the firms name and the coefficient for each firm?

      Comment


      • #4
        You're not telling us enough about your dataset to advise.

        Comment


        • #5
          Sorry about that. I have unbalance panel dataset. each observation has firm_id, indsutry_ id_ , and year. the firm_id is unique for each firm and the industry_id is the same for the firms within the same industry. the firms industry_id is the same during its life. I attached here sample of my data set to be more clear.
          y x1 x2 x3 indsutry_id year firm_name firm_id
          -0.1661 0.0006 0.2778 1.177 28 2003 ABH 2001
          0.0036 0.0004 -0.0818 1.438 28 2004 ABH 2001
          0.0900 0.0003 0.1088 1.204 28 2005 ABH 2001
          -0.2113 0.0002 0.1477 0.959 28 2006 ABH 2001
          -0.1290 0.0002 -0.3144 0.082 28 2007 ABH 2001
          -0.5733 0.0019 0.9714 0.884 28 2008 ABH 2001
          -1.0442 0.0015 0.7703 0.689 28 2009 ABH 2001
          1.1014 0.0015 2.2224 0.870 28 2010 ABH 2001
          -0.0524 0.0000 0.4367 0.633 33 2004 ACER 2002
          -0.0112 0.0000 0.1329 0.489 33 2005 ACER 2002
          -0.0577 0.0000 -0.1377 0.346 33 2006 ACER 2002
          0.0169 0.0000 -0.0479 0.571 33 2007 ACER 2002
          -0.2117 0.0004 1.6679 0.339 44 2005 ACMG 2003
          -0.1138 0.0002 -0.0617 0.203 44 2006 ACMG 2003
          0.2680 0.0002 -0.0694 0.185 44 2007 ACMG 2003
          0.0162 0.0002 1.1136 0.219 44 2008 ACMG 2003
          -0.0581 0.0001 0.5760 0.076 44 2009 ACMG 2003
          0.1675 0.0000 -0.1819 0.061 44 2010 ACMG 2003
          -0.0005 0.0000 0.1555 0.071 44 2011 ACMG 2003
          -0.1809 0.0000 -0.0973 0.064 44 2012 ACMG 2003
          -0.2377 0.0001 -0.1323 0.096 44 2013 ACMG 2003
          -0.5096 0.0002 -0.3802 0.003 87 2002 ACV 2006
          0.1224 0.0024 0.0000 0.033 87 2003 ACV 2006
          -0.1596 0.0002 -0.0515 1.282 80 2002 AD. 2007
          0.1084 0.0003 -0.0424 1.513 80 2003 AD. 2007
          0.0099 0.0002 0.1146 2.212 80 2004 AD. 2007
          0.1754 0.0001 0.2074 1.264 80 2005 AD. 2007
          0.0146 0.0001 -0.0024 0.997 80 2006 AD. 2007
          -0.0198 0.0001 0.0477 1.118 80 2007 AD. 2007
          -0.0305 0.0001 0.0205 0.844 80 2008 AD. 2007
          -0.0186 0.0001 -0.0323 0.757 80 2009 AD. 2007
          -0.1884 0.0030 0.9119 0.383 56 2008 ADIL 2008
          -0.2084 0.0009 0.1705 0.187 56 2009 ADIL 2008

          Comment


          • #6
            If there's a one-to-one correspondence between firms and industries, it's a simple merge.

            Comment

            Working...
            X