Hi, I'm just getting back into Stata after a long illness, so I could use some help. I'm trying to run the following code to output proportions to an excel file. It runs through A`'j' but fails at C`j' and returns error code _=invalid name r(198). Can anyone suggest a fix?
Here's my code:
local j = 2
foreach v of varlist agecat gender education incomecat race {
svy,subpop(if child==1): prop `v',over(year)
matrix results = r(table)
matrix results = results[1...,1...]'
putexcel set "$results\Table 1.xlsx", sheet("Categorical vars") modify
putexcel A`j' = "`v'"
local l = rowsof(results)
forvalues `i' = 0(1)`l' {
local i = `i' + 1
local j = `j' + 1
putexcel C`j' = results[`i',1] J`j' = results[`i',2]
/*Above is the point of failure at C`j'*/
local i = `i' + 1
putexcel D`j' = results[`i',1] K`j' = results[`i',2]
local i = `i' + 1
putexcel E`j' = results[`i',1] L`j' = results[`i',2]
local i = `i' + 1
putexcel F`j' = results[`i',1] M`j' = results[`i',2]
local i = `i' + 1
putexcel G`j' = results[`i',1] N`j' = results[`i',2]
local i = `i' + 1
putexcel H`j' = results[`i',1] O`j' = results[`i',2]
}
local j = `j' + 2
}
Related Posts with _= invalid name r(198)
Grouping small communities to avoid small cell problemHello everyone, Thank you for your help in advance! I am quite desperate at this moment as this sho…
Grouping Households in Panel Data Based on IdentifiersHi All, I am trying to follow households over time in a panel dataset. Currently, each individual h…
Loop with a conditionDear All First time poster. Using Stata 15.1 on Windows. I am doing a epidemiologic register study…
Generate date on conditionDear all Please advise how I can replace "extr_date" ONLY for id's where "age2019" is less than 18 …
Estimating effect of lagged changes on wealth accumulationHi Everyone! I am trying to estimate the effect of a lagged independent variable on wealth accumula…
Subscribe to:
Post Comments (Atom)
0 Response to _= invalid name r(198)
Post a Comment