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"
Markov switching model with few time seriesHi everyone, I have times series with 11 observations on the business climate index. Can I apply Mar…
Creating subgroups in panel dataI am working with a panel of UK industries from 1997-2018, and wish to group some of these industrie…
Panel data - removing individuals if criteria is not met in each yearHi. I have panel data from 2009-2016. I want to remove individuals from the data set if the variable…
How to generate a variable that uses other variables when I have missing valuesI am trying to generate a variable (CSSD) for dispersion which is equal to the sum of the squared de…
Dropping group of variables if the group does not contain a certain valueDear all, I am a stata beginner so this question might sound stupid. I have a dataset that list per…
Subscribe to:
Post Comments (Atom)
0 Response to Run simple regression over a subsample by "in"
Post a Comment