Hello everyone, I am new to Stata and woud like your help. I have a sample of size 249, and I would like to run a regression over the first 50 observations. The only way I know is to create a sequence variable and use "if", and it works (the blue line). I was wondering if I can use "in" instead? (the red line)
When I run the following code, I got an error message "'50-start_T+1' invalid observation number"
clear all
import excel "data/xyz.xlsx", firstrow case(lower) clear
egen t1 = seq()
tsset t1
sca n1 = 65
sca start_T = 50
gen b_cons = .
gen b_x1 = .
gen b_x2 = .
gen y_f = .
forvalues i = `=start_T'/`=_N-n1' {
//reg y x1 x2 if t1<= `i' & t1> `i'-start_T // it works
reg y x1 x2 in `i'-start_T+1/`i' // it does not work; error
predict temp in `i+n1'
replace y_f = temp in `i+n1'
drop temp
}
I would like to know how to do it because "if" does not extend to more advanced models, but I hope "in" can.
Related Posts with Run simple regression over a subsample by "in"
gen id = _nDear All, Consider the following case, Code: clear set seed 12345 set obs 20000000 gen id = _n We c…
P for trend in MV regressionhi all, basic question - if I am running an MV regression as below, where can I find the "P for tren…
Multilevel model: about the decision of levelsHi Everybody, I'm using a panel data (from year 2013 to 2020) about firms' R&D, sales, region of…
Graph svy total with confidence intervalsHi Is there any way to make a graph of a estimate total with 95% confidence intervals of a variable …
Generating and exporting summary table to ExcelHello, I am trying to produce a table that offers some summary statistics (Ns and %s, and averages, …
Subscribe to:
Post Comments (Atom)
0 Response to Run simple regression over a subsample by "in"
Post a Comment