It is almost impossible to determine whether most caterpillars are male or female. Caterpillars are the juvenile life stage of butterflies and moths -- they don't mate or reproduce. While most are genetically either male or female, their reproductive organs don't develop until they're pupae, transforming into adults. However, you can make a good guess at the sex of a few species depending on the translucency of their skin and determine the sex of at least one species as soon as it pupates.
Specific Translucent Caterpillars
Cephrenes augiades is the taxonomic name for the orange palm dart butterfly. These small orange and black Australian butterflies lay their eggs on certain palm tree species, where the caterpillars spend their lives all the way through pupation. The nocturnal caterpillars have black and brown heads and translucent blue and green bodies that make them one of the few caterpillars whose gender can be determined. Both sexes have a dark line down their backs. The males' undeveloped testes are visible as yellow globes beneath the skin on either side of this line between the middle and tail end of the body. The older the caterpillar is, the more visible the testes.
Other Translucent Caterpillars
If you've found another translucent species of caterpillar, you may be able to tell its gender in the same way as Cephrenes augiades: simply look down at it from above. If you see yellow or reddish globes beneath the skin on either side of the dorsal line and toward the rear of the caterpillar, it's probably male.
Male and female monarch butterfly caterpillars look identical -- but if you care for one until it pupates, you'll be able to determine its sex. The pupa attaches to a stable object by a tiny black structure called the "cremaster." A black pattern extends from the cremaster onto the body of the pupa. It ends in a pair of dots. Just beneath these dots, on the side of the pupa pointing away from the cremaster, females have a small vertical line. Male monarch pupae lack this line. Both have a vertical line closer to the cremaster, so make sure you are looking below the dots.
The sex of most butterflies and moths is determined genetically at the moment of fertilization and most are either male or female, but gynandromorphs, which have both male and female characteristics, are fairly common. Gynandromorphy happens when one of the chromosomes mutates during development. Bilateral gynandromorphs have one male side of the body and one female side. Mosaic gynandromorphs have differently sexed portions scattered randomly throughout their bodies.
Many butterfly and moth species also host Wolbachia bacteria, which are able to transform genetic males into reproductive females, as well as cause females to produce young without insemination -- though none of these conditions are visibly apparent at the caterpillar stage.