+ Reply to Thread
Page 2 of 2 FirstFirst 1 2
Results 16 to 27 of 27

Thread: how to regress data by industry by year?

  1. #16
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?



    thanks again for your quick responses to my questions.

  2. #17
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?

    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.

  3. #18
    RoboStataRaptor
    Points: 7,301, Level: 56
    Level completed: 76%, Points required for next Level: 49
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,015
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to regress data by industry by year?

    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.

  4. #19
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?

    OMG!!! I need to start it again. I will try to use the way you suggested to me.

  5. #20
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?

    . 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.

  6. #21
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?

    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.

  7. #22
    RoboStataRaptor
    Points: 7,301, Level: 56
    Level completed: 76%, Points required for next Level: 49
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,015
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to regress data by industry by year?

    So I think you're saying that you've got it working now?

  8. #23
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?

    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'
    }

  9. #24
    RoboStataRaptor
    Points: 7,301, Level: 56
    Level completed: 76%, Points required for next Level: 49
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,015
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to regress data by industry by year?

    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'
            }
        }
    }

  10. #25
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?

    I am so grateful for all your helps. I did it but it informed me that -last estimates not found r(301);-.

  11. #26
    RoboStataRaptor
    Points: 7,301, Level: 56
    Level completed: 76%, Points required for next Level: 49
    bukharin's Avatar
    Location
    Sydney, Australia
    Posts
    1,015
    Thanks
    9
    Thanked 240 Times in 233 Posts

    Re: how to regress data by industry by year?

    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=.")?

  12. #27
    Points: 55, Level: 1
    Level completed: 10%, Points required for next Level: 45

    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: how to regress data by industry by year?


    I got it after I copy and paste your commands. Thanks a lot. You save my life indeed.

+ Reply to Thread
Page 2 of 2 FirstFirst 1 2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats