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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:55:43+00:00 2026-06-17T10:55:43+00:00

I looking for a way to estimate various models (lets say 10) and save

  • 0

I looking for a way to estimate various models (lets say 10) and save a certain parameter value from each estimation in a vector with stata.

Im more of a R-guy and here it is very simple working example with R-code

n1 <- 100
n2 <- 10
group <- rep(1:10,each=n1)
data <- as.data.frame(cbind(rnorm(n1*n2,0,1),rnorm(n1*n2,0,1),group))
dimnames(data)[[2]] <- c("y","x","group")
val <- names(table(group))
estimates <- vector(mode="numeric",length=length(val))

for( i in 1:length(val)){
j <- which(data$group==val[i])
estimates[i] <- coef(lm(y[j] ~ x[j], data=data))[2]
}

Alternatively

library(nlme)
mod1 <- lmList(y~x | group, data=data)
coef(mod1)[,2]

And yes, unfortunately I need to use stata 🙁

  • 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-17T10:55:44+00:00Added an answer on June 17, 2026 at 10:55 am

    What is you ultimate objective? The paradigms of Stata and R are different, so knowing the ultimate goal would help. In R I tend to think in terms of vectors, but not in Stata (vectors don’t really exist in Stata). If you want a table, then I suggest the estout package from SSC (ssc install estout). If just want the coefficients as an end in themselves, then I suggest statsby.

    clear
    version 11.2
    set seed 2001
    
    * generate your data
    set obs 1000
    generate y = rnormal()
    generate x = rnormal()
    generate group = 1 + floor((_n - 1) / 100)
    
    * if you want a table
    * you'll need the estout package from SSC (ssc install estout)
    eststo clear
    forvalues i = 1/10 {
        eststo : regress y x if (group == `i')
    }
    esttab
    
    * if you just the coefficients
    statsby, by(group) clear : regress y x
    list
    

    Both esttab and statsby have lots of options, so check out the help files.


    Update: It seems you want time series betas by group (here a firm). In terms of economics I think you would want rolling regressions, but this framework should get you started.

    clear
    version 11.2
    set seed 2001
    
    * generate your data
    set obs 1000
    generate y = rnormal()
    generate x = rnormal()
    generate firm = 1 + floor((_n - 1) / 100)
    generate year = 1 + mod((_n - 1), 100)
    
    * regress by firm
    xtset firm year
    statsby _b, by(firm) saving(temp, replace) : regress y x
    
    * then merge back
    merge m:1 firm using temp
    list in 1/20
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for way to parse the strikeout / strikethrough value of cells
I am looking for a way to estimate which developer contributed the most code
I'm looking for a good way to estimate the power of a signal (regularly
I am looking for a way to estimate how much extra storage will be
Is there any fast (and nice looking) way to remove an element from an
I'm looking for way to create list view as like in IOS with pinned
I'm looking a way to enable IP logging with log4net in ASP.NET. I found
I'm looking for way to write Javascript programs / scripts on desktop, not inside
I'm looking a way to build conditional assignments in bash: In Java it looks
I am using codeigniter and looking a way to enable directly editting of doc

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.