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

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

```I found this in my files. No help file
was written. It does the area bit.

Feed it the x and y coordinates of the
polygon vertices. The syntax is

polyarea xvar yvar [in]

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

tokenize `varlist'
args x y

marksample touse, novarlist
qui count if `touse' & (missing(`x') | missing(`y'))
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' * ///
(`x'[_n + 1] - `x') * (`y'[_n + 1] + `y') / 2
qui replace `area' =       ///
(`x'[`r(min)'] - `x') * (`y'[`r(min)'] + `y') / 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
>
> how can I calculate the area and the center (of gravity) of
> a polygon
> (triangle, square, pentagon) in Stata?
>
> I have got data on the coordinates of the points forming
> the polygon. My
> goal is to calculate spatial models for my PhD in political science.
>

*
*   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/
```