do you mean I cannot use -predict- command after-by ind year,sort: regress ta chgrev ppe-?. I run this command and then use the command-predict-. It still generated the predicted values.
thanks again for your quick responses to my questions.
do you mean I cannot use -predict- command after-by ind year,sort: regress ta chgrev ppe-?. I run this command and then use the command-predict-. It still generated the predicted values.
You can use it but it will generate the predictions based on the most recently run model - I don't think this is what you want. To generate a prediction from each model, specific to the observations (subset of dataset) included in that model, you have to run -predict- after each model which is what the loop above does.
OMG!!! I need to start it again. I will try to use the way you suggested to me.
. tempvar ta
. levelsof sic, local(levels)
1 2 8 9 13 14 15 16 17 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 41 42 44 45 47
> 48 49 50 51 53 54 56 58 59 70 73 79 80 82 87 99
. foreach x of local levels {
2. foreach z of numlist 1993/2011 {
3. capture reg ta chgrev ppe if sic==`x' & year==`z'
4. if !_rc==2000 {
5. local oldrc = _rc
6. Break key and error cleanup code
7. exit `oldrc'
8. predict `ta'
9. replace ta2=`ta' if e(sample)
10. drop `ta'
11. }
12. }
13. }
.
Do you have any idea about these commands? I have tried to follow the manual but it still does not work.
capture {
stata commands
}
if _rc!=0 {
local oldrc = _rc
Break key and error cleanup code
exit `oldrc'
}
(program continues: :
These are from the manual. However, I just used Stata a few days ago so that it's very complicated to me.
So I think you're saying that you've got it working now?
Nope. it is because I have to put -Break key and error cleanup code-. But I have not known where I can get it even in the manual. The manual gives me that:
capture {
stata commands
}
if _rc!=0 {
local oldrc = _rc
Break key and error cleanup code
exit `oldrc'
}
So to summarise the advice so far:
Code:gen ta1=. tempvar ta levelsof sic, local(levels) foreach x of local levels { foreach z of numlist 1992/2012 { capture reg ta chgrev ppe if sic==`x' & year==`z' if !_rc { predict `ta' replace ta1=`ta' if e(sample) drop `ta' } } }
I am so grateful for all your helps. I did it but it informed me that -last estimates not found r(301);-.
Are you sure there are no typos in this line:
if !_rc {
If yes, can you please copy and paste the exact output from the results window (starting with "gen ta1=.")?
I got it after I copy and paste your commands. Thanks a lot. You save my life indeed.
|
|