Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3954204
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:04:07+00:00 2026-05-20T02:04:07+00:00

I have a balanced panel by country from 1951 to 2007 in a data

  • 0

I have a balanced panel by country from 1951 to 2007 in a data frame. I’d like to transform it into a new data frame of five year averages of my other variables. When I sat down to do this I realized the only way I could think to do this involved a for loop and then decided that it was time to come to stackoverflow for help.

So, is there an easy way to turn data that looks like this:

country   country.isocode year      POP           ci      grgdpch
Argentina             ARG 1951 17517.34 18.445022145 3.4602044759
Argentina             ARG 1952 17876.96  17.76066507 -7.887407586
Argentina             ARG 1953 18230.82 18.365255769 2.3118720688
Argentina             ARG 1954 18580.56 16.982113434 1.5693778844
Argentina             ARG 1955 18927.82 17.488907008 5.3690276523
Argentina             ARG 1956 19271.51 15.907756547 0.3125559183
Argentina             ARG 1957 19610.54 17.028450999 2.4896639667
Argentina             ARG 1958 19946.54 17.541597134 5.0025894968
Argentina             ARG 1959 20281.15 16.137310492 -6.763501447
Argentina             ARG 1960 20616.01 20.519539628  8.481742144
...
Venezuela             VEN 1997 22361.80 21.923577413  5.603872759
Venezuela             VEN 1998 22751.36 24.451736863 -0.781844721
Venezuela             VEN 1999 23128.64 21.585034168 -8.728234466
Venezuela             VEN 2000 23492.75 20.224310777 2.6828641218
Venezuela             VEN 2001 23843.87 23.480311721 0.2476965412
Venezuela             VEN 2002 24191.77 16.290691319  -8.02535946
Venezuela             VEN 2003 24545.43 10.972153646 -8.341989049
Venezuela             VEN 2004 24904.62 17.147693312 14.644028806
Venezuela             VEN 2005 25269.18 18.805970212 7.3156977879
Venezuela             VEN 2006 25641.46 22.191098769 5.2737381326
Venezuela             VEN 2007 26023.53 26.518210052 4.1367897561

into something like this:

country   country.isocode period   AvPOP     Avci Avgrgdpch
Argentina             ARG      1   18230 17.38474  1.423454
...
Venezuela             VEN     12   25274 21.45343  5.454334

Do I need to transform this data frame using a specific panel data package? Or is there another easy way to do this that I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T02:04:07+00:00Added an answer on May 20, 2026 at 2:04 am

    This is the stuff aggregate is made for. :

    Df <- data.frame(
        year=rep(1951:1970,2),
        country=rep(c("Arg","Ven"),each=20),
        var1 = c(1:20,51:70),
        var2 = c(20:1,70:51)
    )
    
    Level <-cut(Df$year,seq(1951,1971,by=5),right=F)
    id <- c("var1","var2")
    
    > aggregate(Df[id],list(Df$country,Level),mean)
      Group.1     Group.2 var1 var2
    1     Arg [1951,1956)    3   18
    2     Ven [1951,1956)   53   68
    3     Arg [1956,1961)    8   13
    4     Ven [1956,1961)   58   63
    5     Arg [1961,1966)   13    8
    6     Ven [1961,1966)   63   58
    7     Arg [1966,1971)   18    3
    8     Ven [1966,1971)   68   53
    

    The only thing you might want to do, is to rename the categories and the variable names.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a big panel of data from Compustat. To it I am adding
I have a scenario that my load balancer translates port 80 from outside into
I have 3 websites that run from a load-balanced pool of servers. Load-balancer uses
We have a website load balanced across two servers that calls into a WCF
I have a set of strings that need to be load-balanced into 1 of
I have 2 load balanced web servers. My application is using the SQL Server
I have two load balanced servers each running exactly the same copy of various
I have found the following resources on Balanced Matching for .net Regexes: http://weblogs.asp.net/whaggard/archive/2005/02/20/377025.aspx http://blogs.msdn.com/bclteam/archive/2005/03/15/396452.aspx
I have an environment where 2 load-balanced clustered tomcats pointing to same application. When
I have a bunch of EC2 servers that are load balanced. Some of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.