I am supposed to write a programme called vx, that takes on the value of 1 if the variable’s value is in the top 5th percentile and 0 otherwise and error if input variable is categorical variable.
capture program drop vx
program vx
syntax varname
su `varlist'
if var == factor {
display "Invalid argument: Input variable is not a categorical variable"
}
else var >= `r(p95)' {
display "1"
}
else var < `r(p95)' {
display "0"
}
}
end
I ran the programme on 3 variables: length, mass and weight. I ended up with the error 111, which said var could not be found. Is there a way to remedy the programme?
capture program drop vx
program vx
syntax varname
su `varlist'
if var == factor {
display "Invalid argument: Input variable is not a categorical variable"
}
else var >= `r(p95)' {
display "1"
}
else var < `r(p95)' {
display "0"
}
}
end
I ran the programme on 3 variables: length, mass and weight. I ended up with the error 111, which said var could not be found. Is there a way to remedy the programme?
Comment