Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to run a loop

    HI i'm a new user in mata and i'm trying to run a loop but i got an error message that says 'expectedValueFunctionnCapitalnProductivity' found where almost anything else expected

    Here's the code

    while(maxDifference > tolerance){
    for(nProductivity = 0; nProductivity < nGridProductivity; nProductivity++){
    for(nCapital = 0; nCapital < nGridCapital; nCapital++){
    expectedValueFunctionnCapitalnProductivity = 0.0;
    }
    }
    else{
    for(nProductivityNextPeriod = 0; nProductivityNextPeriod < nGridProductivity; nProductivityNextPeriod++){
    expectedValueFunctionnCapitalnProductivity = mTransitionnProductivitynProductivityNextPeriod * mValueFunctionnCapitalnProductivityNextPeriod;
    }
    }
    }

    Can someone help me ?

  • #2
    Hi Luisa
    I can't figure out what you are doing, but semicolons aren't necessary.
    And there is an "else{" with out an if.
    Indentions will make your code more readable.
    And some of your variable names are too long for my taste.

    I've tried to guess what you wanted below:
    Code:
    while(maxDifference > tolerance){
        for(nProductivity = 0; nProductivity < nGridProductivity; nProductivity++){
            for(nCapital = 0; nCapital < nGridCapital; nCapital++){
                expectedValueFunctionnCapitalnProductivity = 0.0
            }
        }
    }
    //else{
    for(nProductivityNextPeriod = 0; nProductivityNextPeriod < nGridProductivity; nProductivityNextPeriod++){
        expectedValueFunctionnCapitalnProductivity = mTransitionnProductivitynProductivityNextPeriod * mValueFunctionnCapitalnProductivityNextPeriod
    }
    Kind regards

    nhb

    Comment


    • #3
      Thank you so much, I-m having tons of problems with the code, I think it was translated in a bad way.
      By theh way, do you know how to declare an integer variable that will be used later.... for example nCapital is an entry of a 17820x5 matrix

      Regards,
      Luisa Riascos

      Comment

      Working...
      X