Hello,
I am using StataMP 18 on windows 10.
I have a variable "citypart" that describes from 1 to 99 in which city part of my city participants live in. I also have a variable called "propfem" that describes the proportion of females in each city part (so correspondingly coded from 1 to 99). Furthermore I have the variable "sex" that tells me if a participant is 1 = female.
Now I want to check for each city part if the proportion of females in my dataset is approx. equal to the actual proportion of females in that city part.
I came up with the following code:
This technically gives me my desired results but this way the ttest is computed not merely for the corresponding value of propfem but for all values of propfem. Since I have 99 city parts this takes a lot of time and giving me a lot of unnecessary results. Is there a way that I can get the ttest only for the corresponding values of citypart & propfem?
Any advice is highly appreciated
I am using StataMP 18 on windows 10.
I have a variable "citypart" that describes from 1 to 99 in which city part of my city participants live in. I also have a variable called "propfem" that describes the proportion of females in each city part (so correspondingly coded from 1 to 99). Furthermore I have the variable "sex" that tells me if a participant is 1 = female.
Now I want to check for each city part if the proportion of females in my dataset is approx. equal to the actual proportion of females in that city part.
I came up with the following code:
Code:
levelsof citypart, local(citypartlevels)
foreach 1 of local citypartlevels{
sum sex if citypart== `1'
local N_1 = r(N)
local av_1 = r(mean)
local sd_1 = r(sd)
levelsof propfem, local(propfemlocal)
foreach 1 of local propfemlocal{
sum propfem if propfem== `1'
local meanpropfem = r(mean)
ttesti `N_1' `av_1' `sd_1' `meanpropfem'
}
}
Any advice is highly appreciated

Comment