Announcement

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

  • Making a loop

    Dear Stata users,

    I would like your help for the following problem. I have a data set with 22 countries and 20 years and a variable Total Assets (TA). Below you can see an example of the data base.

    Click image for larger version

Name:	Stata Loop.png
Views:	1
Size:	5.5 KB
ID:	1348821


    I would like to make a loop to create variables that show the Total Assets of the entire country per year, per country. So the data set would look like this.


    Click image for larger version

Name:	Stata Loop2.png
Views:	1
Size:	11.4 KB
ID:	1348822


    Now I'm using the codes:
    egen TM_A_1995 = sum(TA) if Country ==1 & Year == 1995
    egen TM_A_1995 = sum(TA) if Country ==1 & Year == 1996
    etc.

    Can someone please help me with creating a loop?

    Thank you in advance.

  • #2
    Why do you (think you) need so many variables? Put all the totals in one variable; and no loop is needed.

    Code:
    egen Total_TA = total(TA) , by(Country Year)
    Note that the egen function sum() is undocumented as of Stata 9. total() is the current name. If you are using Stata 8 or earlier, you should be telling us that. http://www.statalist.org/forums/help#version

    Comment

    Working...
    X