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

  • Home
  • SEARCH
  • 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 3678100
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:18:03+00:00 2026-05-19T03:18:03+00:00

I have data that is organized in panels like this (see below for output

  • 0

I have data that is organized in panels like this (see below for output from the dput() function):

Country Year Month Var1 Var2
C1      2000 1     0    0
C1      2000 2     1    0
C1      2000 3     2    1
...  
C2      2000 1     1    1
C2      2000 2     1    2
C2      2000 3     3    1
...

The data set has in total 27 countries for the years 1999 to 2008, but with unbalanced panels.

I want to be able to estimate a model for the full data set, and from this model do forecasting for each country in the data set. I have been looking into the YourCast package from King et al. but since I have all my data in a single file, I am at a loss as to how to create a data object that the yourcast() function will accept. Does anyone know how to do this without going through the tedious procedure of manually splitting the data file up into the different cross sections?

PS: 48 observations from the data set:

structure(list(Country = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Belgium", 
"Denmark", "Czech.Republic", "Germany", "Estonia", "Greece", 
"Spain", "France", "Ireland", "Italy", "Cyprus", "Latvia", "Lithuania", 
"Luxembourg", "Hungary", "Malta", "Netherlands", "Austria", "Poland", 
"Portugal", "Slovenia", "Slovakia", "Bulgaria", "Romania", "Finland", 
"Sweden", "UK"), class = "factor"), Year = c(2003, 2003, 2003, 
2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2004, 2004, 
2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2003, 
2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 2003, 
2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 2004, 
2004, 2005), Month = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 
9, 10, 11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1), Yes = c(21L, 
18L, 20L, 19L, 31L, 39L, 28L, 2L, 28L, 21L, 26L, 50L, 14L, 28L, 
50L, 83L, 10L, 25L, 22L, 6L, 22L, 39L, 32L, 56L, 22L, 17L, 20L, 
20L, 32L, 39L, 23L, 2L, 27L, 21L, 28L, 48L, 14L, 27L, 50L, 89L, 
10L, 25L, 22L, 4L, 22L, 38L, 31L, 56L, 16L), No = c(0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 4L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 
0L, 0L, 0L, 1L, 2L, 0L,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, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L), Missing = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), Enlargement = c(0, 0, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1)), .Names = c("Country", "Year", "Month", "Yes", 
"No", "Abstention", "No.Neg", "Abstention.Neg", "Yes.Neg", "Yes.Pos", 
"Missing", "Enlargement"), row.names = c(1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 
19L, 20L, 21L, 22L, 23L, 24L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 
68L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 
81L, 82L, 83L, 84L, 85L), class = "data.frame")
  • 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-19T03:18:04+00:00Added an answer on May 19, 2026 at 3:18 am

    If I understand your problem, splitting up the database could be quite easy. Supposing you named the dataset ‘data’:

    results <- list()
    for (i in 1:nlevels(data$Country)) {
        results[[levels(data$Country)[i]]] <- yourcast(...)
    }
    

    In which simple loop you could do all forecasting to each country, and save the results to a list. Later you can read all results from the results list for all countries. E.g.: results[['Hungary']]

    As I do not know anything about the package you use, here is a small example that could be fitted in the loop instead of the line containing yourcast() function:

    results[[levels(data$Country)[i]]] <- c(levels(data$Country)[i], length(which(data$Country == levels(data$Country)[i])))
    

    Which command will create a list containg all countries with two variables: name and sample size of given country.

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

Sidebar

Related Questions

I have a query that returns rows in the following format: ID NAME PARENTID
I have a form that requires a physical address. Once the user enters the
Suppose that I have users, tasks and each task belongs to a batch. Each
Please help, how can I organize the process-process data exchange (in Windows, if that
I have a collection of stuffs in a generic Dictionary<string, object>() . The key
I have a drag and drop application (which allows users to organize their files)
I'm trying to write a fairly simple application in C# (or at least, I
I am always reading about keeping Controllers thin and doing all logic in models.
i am in the early stages of designing a VERY large system (its an
I was asked to make some kind of reporting (logging) service. The employee has

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.