Announcement

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

  • Problem with loop

    I have to compute the relative mean weight of two variables (local taxes called IMI and IMT) considering the total income (over two other variables, called Capital Income and Current Income), using loop-foreach. However, the below comand, that I've been trying, is not working.

    local llist "IMI IMT"

    . foreach cc of local llist {
    2.
    . display _new _new "Local tax: `cc'"
    3.
    . keep if IMI == "`cc'" | IMT == "`cc'"
    4.
    . reg Cap Cor
    5.
    . }

    Can someone help please?

  • #2
    The keep line is going to shrink your dataset to the condition, and not return to its original state.

    I suppose you could

    reg Cap Cor if IMI == "`cc'" | IMT == "`cc'"

    or

    preserve
    keep if ...
    reg ...
    restore

    A dataex of some of your data would help.

    Not obvious what you are using reg for, as it will provide a partial correlation coefficient between the two, not the mean.
    Last edited by George Ford; 01 May 2024, 10:36.

    Comment

    Working...
    X