Dear all,
I have a variable of the form income_yyyy_mm where 'yyyy' refers to the year and 'mm' refers to the month. The variable shows the income status of an individual, and the value '.' means no income.
I have another variable again of the form xyyyy_mm where 'yyyy' again refers to the year and 'mm' refers to the month. I need this variable to take the value 1, if the individual had no income in the previous month.
Writing
returns
which is because there is no "month zero" of my data in 2014. I need the first line to refer to month 12 in the preceding year. My own suggestion of solving the first part of this problem, i.e., making ´k' show 12 if `i' is 1 does not work. Writing:
Returns
I do know that there are two parts of my problem (because of the years also need to change) but I believe I could solve the year-part of the problem, if I understood how to solve the month part of the problem. So how do I replace the value of local macro if the local macro takes on a specific value?
I have a variable of the form income_yyyy_mm where 'yyyy' refers to the year and 'mm' refers to the month. The variable shows the income status of an individual, and the value '.' means no income.
I have another variable again of the form xyyyy_mm where 'yyyy' again refers to the year and 'mm' refers to the month. I need this variable to take the value 1, if the individual had no income in the previous month.
Writing
Code:
forval i = 1/12 { forval j = 2014/2021 { local k = `i' - 1 replace x´j'_´i' = 1 if /// income_´j'_´i' ==. } }
Code:
income_2014_0 not found
Code:
forval i = 1/12 { forval j = 2014/2021 { local k = `i' - 1 replace `k'=12 if `k'==0 replace x´j'_´i' = 1 if /// income_´j'_´i' ==. } }
Code:
0 invalid name
Comment