# st: RE: RE: how determine area and center of polygon (triangle, square, pentagon) in Stata ???

 From "Nick Cox" To Subject st: RE: RE: how determine area and center of polygon (triangle, square, pentagon) in Stata ??? Date Wed, 26 Nov 2003 15:30:29 -0000

```Yes. I've removed Stata 8 details, but not
tested this. If it doesn't work, please
let me know privately.

*! NJC 1.0.0 15 August 2003
program polyarea7, rclass
version 7
syntax varlist(min=2 max=2 numeric) [in]

tokenize `varlist'
args v1 v2

marksample touse, novarlist
qui count if `touse' & (missing(`v1') | missing(`v2'))
if r(N) {
di as err "missing values in data"
exit 198
}

tempvar order area

gen long `order' = _n
su `order' if `touse', meanonly

qui gen `area' = `touse' * /*
*/ (`v1'[_n + 1] - `v1') * (`v2'[_n + 1] + `v2') / 2
qui replace `area' = /*
*/ (`v1'[`r(min)'] - `v1') * (`v2'[`r(min)'] + `v2') / 2 in `r(max)'
su `area', meanonly

di as res %9.0g abs(r(sum))
return scalar area = abs(r(sum))
end

Nick
n.j.cox@durham.ac.uk

Dietrich Drüner
>
> thanks very much already! but unfortunately it didn't work
> yet with your program, I get an error message "invalid
> syntax" already after the line
>
> "program polyarea, rclass"
>
> I am using version 7, could this cause the problem?
> Do I need the part about missing values, even if there are
> no missing in my data?
> Has "varlist" to be replace by my x and y variables, too?
>
> Below is the do-file I used, adapted to the data set I
> attached as well:
>
> Would be great, if you could have a look at it!
>

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```