Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

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


From   "Dietrich Dr�ner" <[email protected]>
To   [email protected]
Subject   st: RE: how determine area and center of polygon (triangle, square, pentagon) in Stata ???
Date   Wed, 26 Nov 2003 16:13:17 +0100

Dear Nick,

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!

Thanks!

Dietrich.
_______________________________________________


*polyarea xvar yvar [in]
*belongs to program?

*! NJC 1.0.0 15 August 2003
program polyarea, 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

______________________________________________

[email protected] schrieb am 26.11.03 14:33:00:
> 
> 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
> [email protected]
> 
>
~~~~~~~~~~~~~~~~~~~~~~~~

Dietrich�Dr�ner
Schneckenburgstr.�24
D�-�78467�Konstanz

Tel.�(+49)�-�7531�-�698003
Fax�(+49)�-�1212�-�522970813
Mob.(Inland):�(+49)�-�177�-�6334099
Mob.(Ausland):(+49)�-�162�-�7679952

~~~~~~~~~~~~~~~~~~~~~~~~

Attachment: cmcored98134.dta
Description: Binary data




© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index