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 8805617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:54:46+00:00 2026-06-14T01:54:46+00:00

I’m trying to run 96 regressions and save the results as 96 different objects.

  • 0

I’m trying to run 96 regressions and save the results as 96 different objects. To complicate things, I want the subscript on one of the covariates in the model to also change 96 times. I’ve almost solved the problem but I’ve unfortunately hit a wall. The code so far is,

for(i in 1:96){

  assign(paste("z.out", i,sep=""), lm(rMonExp_EGM~ TE_i + Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
  Month10+Month11+Month12+Yrs_minus_2004 + 
  as.factor(LGA),data=Pokies))

}

This works on the object creation side (e.g. I have z.out1 – z.out96) but I can’t seem to get the subscript on the covariate to change as well.

I have 96 variables called TE_1, TE_2 … TE_96 in the dataset. As such, the subscript on TE_, the “i” needs to change to correspond to each of the objects I create. That is, z.out1 should hold the results from this model:

z.out1 <- lm(rMonExp_EGM~ TE_1 + Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
  Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies)

And z.out96 should be:

z.out96 <- lm(rMonExp_EGM~ TE_96+ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
  Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies)

Hopefully this makes sense. I’m grateful for any tips/advice.

  • 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-06-14T01:54:47+00:00Added an answer on June 14, 2026 at 1:54 am

    I would put the results in a list and avoid the for loop and assign statements

    You can use a combination of reformulate and update to create your formula

    orig_formula <- MonExp_EGM~ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+
     Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA)
    
    
    te_variables <- paste0('TE_', 1:96) 
    # Or if you don't have a current version of R
    # te_variables <- paste('TE', 1:96, sep = '_')  
    
     new_formula <- lapply(te_variables, function(x,orig = orig_formula) { 
        new <- reformulate(c(x,'.'))
        update(orig, new)})
     ## it works!    
    new_formula[[1]]
    ## MonExp_EGM ~ TE_1 + Month2 + Month3 + Month4 + Month5 + Month6 + 
    ##   Month7 + Month8 + Month9 + Month10 + Month11 + Month12 + 
    ##   Yrs_minus_2004 + as.factor(LGA)
    new_formula[[2]]
    ## MonExp_EGM ~ TE_2 + Month2 + Month3 + Month4 + Month5 + Month6 + 
    ## Month7 + Month8 + Month9 + Month10 + Month11 + Month12 + 
    ## Yrs_minus_2004 + as.factor(LGA)
    
    
    models <- lapply(new_formula, lm, data = pokies)
    

    There should now be 96 elements in the list models

    You can name them to reflect your originally planned nnames

    names(models) <- paste0('z.out', 1:96)
    # or if you don't have a current version of R
    # names(models) <-paste('z.out', 1:96 ,sep = '' )  
    

    and then access a single model by

     models$z.out5
    

    etc

    or create summaries of all of the models

     summaries <- lapply(models, summary)
    

    etc….

     # just the coefficients
     coefficients <- lapply(models, coef)
    
     # the table with coefficient estimates and standard.errors
    
     coef_tables <- apply(summaries, '[[', 'coefficients')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.